 | |  |
 |

terryally
User
Aug 20, 2008, 2:57 AM
Post #1 of 5
(526 views)
Shortcut
|
|
'Where' clause validation
|
Can't Post
|
|
Good morning from England. 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
(This post was edited by terryally on Aug 20, 2008, 3:43 AM)
|
|
|  |
 | |  |
 |

terryally
User
Aug 20, 2008, 8:39 AM
Post #3 of 5
(502 views)
Shortcut
|
|
Re: [terryally] 'Where' clause validation
[In reply to]
|
Can't Post
|
|
Problem solved. Please ignore.
|
|
|  |
 |

terryally
User
Aug 20, 2008, 9:34 AM
Post #4 of 5
(494 views)
Shortcut
|
|
Re: [terryally] 'Where' clause validation
[In reply to]
|
Can't Post
|
|
Apologies to all. Here is the solution. 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
(This post was edited by terryally on Aug 20, 2008, 9:36 AM)
|
|
|  |
 |

Donna
Staff
/ Moderator

Aug 20, 2008, 11:25 AM
Post #5 of 5
(480 views)
Shortcut
|
|
Re: [terryally] 'Where' clause validation
[In reply to]
|
Can't Post
|
|
Hey Terry! Glad to hear you got that sorted out -- thanks for sharing! :) Donna
Hire me! Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.
|
|
|  |
|