Filtering Records To Be Displayed With PHP Include

25 posts by 4 authors in: Forums > CMS Builder
Last Post: May 18, 2016   (RSS)

By gregThomas - May 9, 2016

Hey Kent, 

What type of field is the category in the CMS? Is it a single drop down, or multi select checkbox or drop down?  Can a record have multiple categories?

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi,

The category field is a multi select check box, records can have and in all cases do have multiple categories.

Thanks!

By gregThomas - May 9, 2016

Hi Kent, 

Thanks for clarifying, this solution should make the records load:

// load records from 'all_classes'
list($all_classesRecords, $all_classesMetaData) = getRecords(array(
 'tableName'   => 'all_classes',
 'perPage'     => '10',
 'loadUploads' => true,
 'allowSearch' => false,
 'where'       => "`categories` LIKE '\t". mysql_escape($category) ."\t'",
));

So multi select list options are stored in a tab separated string, for example: 

    3   6   4   2   9    

The code above searches and returns records where the $category value between two tab characters is found.

Let me know if you have any questions. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hey Greg,

Well, I'm still not getting any records to load on the page and there's no error.

Sorry for all the trouble.

My current code is below -

On the page:

<?php
  $category = "nikka-nadia"; // name of category to load
  include("includes/nikka-nadia-classes.php");
?>

On the include:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('/web/sites/greywood/yogamerge.com/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records from 'all_classes'
list($all_classesRecords, $all_classesMetaData) = getRecords(array(
 'tableName'   => 'all_classes',
 'perPage'     => '10',
 'loadUploads' => true,
 'allowSearch' => false,
 'where'       => "`categories` LIKE '\t". mysql_escape($category) ."\t'",
));

?>

also on the include:

<?php foreach ($all_classesRecords as $record): ?>

I wanted to mention that I uses includes on a variety of pages for navigation menus, etc. and I have always had to use a full url path to the include file if the page was buried within a variety of folders, yogamerge.com/classpages/nikkanadia/restorative-flow-test.php

However, that didn't help in this instance.

By gregThomas - May 10, 2016

Hi Kent, 

I think the issue might be that nikka-nadia isn't a valid option. Would it be possible to post an image of how you've got the list field set up? I've attached an example screenshot of what I'm looking for. 

Then I can see what options you have the drop down field.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Grey,

Sure, I attached a screen shot of that area of the admin.

Thanks much.

Kent

By gregThomas - May 10, 2016

Hey Kent,

Looking at the screenshot, it seems the first letter of each word is capitalized in the CMS, I guess this is the case for Nikka-Nadia as well? Perhaps the code needs to be:

<?php
  $category = "Nikka-Nadia"; // name of category to load
  include("includes/nikka-nadia-classes.php");
?>

This is because MySQL LIKE is case sensitive. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Damon - May 10, 2016

Hi,

Can you send in a Support Request with CMS Builder and FTP details so we can take a closer look:
https://www.interactivetools.com/support/email_support_form.php?priority=free

Thanks!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Thanks much Damon,

Just submitted the support request with requested details.

Kent