Load specific Category menu type records into a Multi menu type using category that calls to the database LIKE

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 5, 2013   (RSS)

By gregThomas - July 4, 2013

Hi Zick,

This is a great post! I think I know what is causing the problem. 

As your wood_options field in the 'the_biltmore' section is storing the num as the value, you need to create a where statement that will only retrieve records with that num value from the wood_types section. 

I think you're close with your imploding method, I think your where statement should look like this:

$inString = implode(', ', $the_biltmoreRecord['wood_options:values']);

list($wood_typesRecords, $wood_typesMetaData) = getRecords(array(
  'tableName'   => 'wood_types',
  'where'       => "num IN($inString)",
  'loadUploads' => true,
  'allowSearch' => false,
));

So the inString variable will contain a comma separated list of num values selected from the wood_options field from the biltmore record. This string is then used in the where statement in an IN function. This will only retrieve records with a num value that is in the IN function. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Mikey - July 4, 2013

Greg - thank you!

Your solution did the trick and the records are loading right now.
You're the man!

Zick

By Mikey - July 4, 2013

Hey Greg... thanks again for the help.

So, I plugged in your solution:

$inString = implode(', ', $the_biltmoreRecord['wood_options:values']);

list($wood_typesRecords, $wood_typesMetaData) = getRecords(array(
  'tableName'   => 'wood_types',
  'where'       => "num IN($inString)",
  'loadUploads' => true,
  'allowSearch' => false,
));

...and this works great - if there is an option selected for within "the_biltmore" product record for the category "wood_options".. However, if a "wood_options" is not selected within the multi (Menu Type) called "the_biltmore" it produces the following MySQL Error message. So essentially at least one "wood_options" in the Field Type "list" must be selected from within the "the_biltmore" product record, or the error message is produced. Is there some sort of if statement I can use to check to see if a "wood_options" is selected, otherwise do nothing? Below are a few things I also tried within the category (Menu Type) called "wood_types", with no luck.

 MySQL Error: You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use 
near ')) 
 ORDER BY name ASC' at line 3

I tried changing the ORDER BY name ASC to ORDER BY globalOrder and got the following MySQL Error message.

MySQL Error: You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use 
near ')) 
 ORDER BY globalOrder' at line 3

I also tried ORDER BY dragSortOrder and got the following MySQL Error message.

MySQL Error: You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use 
near ')) 
 ORDER BY dragSortOrder' at line 3

Again thanks for you help!

Zick

By gregThomas - July 5, 2013

Hi Zick,

You could get around this by wrapping the wood_types getRecord function in an if statement that checks if @$the_biltmoreRecord['wood_options:values'] exists. If it doesn't then $wood_typesRecords could be set to an empty array:


  if(@$the_biltmoreRecord['wood_options:values']){
    $inString = implode(', ', $the_biltmoreRecord['wood_options:values']);
    list($wood_typesRecords, $wood_typesMetaData) = getRecords(array(
      'tableName'   => 'blog',
      'where'       => "num IN($inString)",
      'loadUploads' => true,
      'allowSearch' => false,
    ));
  }else{
    $wood_typesRecords = array();
  }

So if no options are selected on the wood_options field a values array isn't created for it by getRecords. So if $the_biltmoreRecord['wood_options:values'] doesn't exist, we set $wood_typesRecords to an empty array. Otherwise the previous getRecords function creates the $wood_typesRecords array as before.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com