Displaying dynamic content

6 posts by 2 authors in: Forums > CMS Builder
Last Post: March 21, 2013   (RSS)

By CommonSenseDesign - March 18, 2013 - edited: March 18, 2013

I've set up CMSB so that my client can add a series of promotional insets, such as the four seen near the bottom of this homepage: http://kathiejordandesign.com.previewdns.com/index.php (Window Treatments, etc). These are stored in a table in the database called "inset-panels", which has a field called "title".

Is there a way that I can set up other pages in CMSB so the client can choose one inset panel from a drop down menu, and have their selection appear on other live pages? Here's a hard coded example of how I'd like that to look: http://kathiejordandesign.com.previewdns.com/services.php.

I've set up the CMSB for the Services page so that the user can choose which record in "inset-tables" they want to use (see attached), but how do I get the corresponding panel to actually appear on the page? I.e. if they choose, say, "Antiques" from the drop down menu, the corresponding Antiques panel appears on the page.

Attachments:

cmsb_002.jpg 69K

Hi Nigel,

The easiest way to do it would be to make two separate MySQL calls to get the full data from your inset-panels:

First, I would change your list field so that the value that is stored is the num value for the record (see attached image).  Then your code on the page should look something like this:

  //Use getRecords to retrieve your pages data
  list($pages, $pagesMetaData) = getRecords(array(
    'tableName'   => 'pages',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $pages= @$pages[0]; // get first record
  if (!$pages) { dieWith404("Record not found!"); } // show error message if no record found


  $inset = mysql_get('inset-panels', $pages['name_of_list_field']);

This is just example code, so you'll need to make some changes to get it to work with your site.

So the getRecords function is being used to retrieve the general content for the page, and contains the drop down list field that allows the user to select an inset-panel. 

The $pages['name_of_list_field] will contain the relevant num value for the record in your inset-panels section. Then the mysql_get function is used to retrieve the contents of the record from the inset-panels section.

The returned array will be in the same format as a getRecords array, and will contain the details of the inset-panels record. For example, you could display the title of the inset panel like this:

<?php echo $inset['title']; ?>

The only problem you might have is the mysql_get function doesn't return meta data (eg, images, who created the record, etc), let me know if you need that data and I'll show you the changes you need to make to get it.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

example_007.png 17K

By CommonSenseDesign - March 19, 2013 - edited: March 19, 2013

Thanks for your advice, Greg.

I've attached one of the sample pages where I would like the inset panel to appear, like a "dynamic" include, as it were. This is how it should look: http://kathiejordandesign.com.previewdns.com/services.php

In CMSB, I've changed the corresponding list field to num, as you suggested. The code I'm using to retrieve the relevant table is as follows:

  list($insets_panelsRecords, $insets_panelsMetaData) = getRecords(array(
    'tableName'   => 'insets-panels',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

You advised changing this to:

  //Use getRecords to retrieve your pages data
  list($pages, $pagesMetaData) = getRecords(array(
    'tableName'   => 'pages',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $pages= @$pages[0]; // get first record
  if (!$pages) { dieWith404("Record not found!"); } // show error message if no record found


  $inset = mysql_get('inset-panels', $pages['name_of_list_field']);

Sorry, but I'm not sure which values I should be changing in your version, and what should remain untouched?

Also, should I be placing

<?php echo $inset['title']; ?>

where I want the panel to appear on the page?

Thanks again.

Attachments:

services_004.php 7K

Perfect! The panel on the right of this page is selected from the panels that were input via the Insets section I set up in CSMB: http://kathiejordandesign.com.previewdns.com/services.php. Exactly how I needed this to work.

Thanks so much for your patience and advice.