'Where' clause validation
4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 20, 2008 (RSS)
By terryally - August 20, 2008 - edited: August 20, 2008
I just want to pass some code by you to get your advice and correct an error message.
The scenario is that I have set up a Lunch Menu using the Multi-record menu type. The menu has Starters, Main Course, Desserts, and Bar - all of which I want to list in each category on the same page. I could not find any instruction about how to achieve this so I assigned the SELECT call as a variable first as illustrated in the code section below.
It works. But I am still getting the error message:
Notice: Undefined variable: lunch_menuRecords in /home/lakesideint/www/www/menu.php on line 6
Notice: Undefined variable: lunch_menuRecords in /home/lakesideint/www/www/menu.php on line 14.
The undefined variables to which it refers are $main and $starter
How do I correct this?
P.S. My test page is http://lakesideint.server266.com/menu.php
$main = $lunch_menuRecords;
list($main, $lunch_menuMetaData) = getRecords(array(
'tableName' => 'lunch_menu',
'where' => 'course="Main"',
));
$starter = $lunch_menuRecords;
list($starter, $lunch_menuMetaData) = getRecords(array(
'tableName' => 'lunch_menu',
'where' => 'course="Starter"',
));
Terry
Re: [terryally] 'Where' clause validation
By terryally - August 20, 2008
Please ignore.
Re: [terryally] 'Where' clause validation
By terryally - August 20, 2008 - edited: August 20, 2008
It seems that CMS Builder is much more efficient that writing a SELECT statement and query.
What I did was to generate the code using the WHERE clause for each category I wanted to display. Remember my categories are "Starter", "Main", "Dessert" etc. The field name of my categories is called "course" so I generated the code for <course="Starter"> and got the following:
list($lunch_menuRecords, $lunch_menuMetaData) = getRecords(array(
'tableName' => 'lunch_menu',
'where' => 'course="Starter"',
));
Which I placed immediately before the loop, viz
<?php
list($lunch_menuRecords, $lunch_menuMetaData) = getRecords(array(
'tableName' => 'lunch_menu',
'where' => 'course="Starter"',
));
?>
<?php foreach ($lunch_menuRecords as $record): ?>
<?php echo $record['item'] ." ". $record['cost'] ?><br/>
<?php echo $record['description'] . " " .$record['notes'] ?><br/>
<?php endforeach; ?>
I then repeat the same for Main Course and Desserts.
So the difference is that I did not place the code at the top of the page before everything else (except the include file: require_once "/my/path/to/cms-admin/lib/viewer_functions.php";) but immediately before the loop.
The results can be viewed at the development site: http://lakesideint.server266.com/dining/menu_lunch.php
Cheers
Terry
Re: [terryally] 'Where' clause validation
By Donna - August 20, 2008
--
support@interactivetools.com