Setting a "where" value from a form selection
11 posts by 2 authors in: Forums > CMS Builder
Last Post: July 5, 2012 (RSS)
By gkornbluth - July 5, 2012 - edited: May 21, 2013
Hi All,
Sorry to have to revisit this, but I’ve come up with a new challenge.
Based on a selected value in the form, I need to be able to filter out a group of records from being displayed if the value in a check box field called male equals '1', but I need to start out with an unfiltered list when the viewer is first loaded.
I’ve tried implementing the approach above, but the page always returns only those records where the value of the check box is either ‘0' or null.
Here’s what I have so far.
In the head of the viewer:
<?php $where = "";
?>
<?php if (@$FORM['where'] == 'a') { $where = '1'; }
if (@$FORM['where'] == 'b') { $where = ' '; }
?>
In the load records statement:
list($attendance_testRecords, $attendance_testMetaData) = getRecords(array(
'tableName' => 'attendance_test',
'where' => " male = '$where' ",
));
In the Form:
<select name="where">
<option value="">Exclude Males?</option>
<option value="b">NO</option>
<option value="a">YES</option>
</select>
It seems that I’ve got to ignore the ‘where’ statement when the value of the checkbox is != 1 (unless there’s a better approach)
I’ve tried things like the code below, but can’t get the syntax correct.
list($attendance_testRecords, $attendance_testMetaData) = getRecords(array(
'tableName' => 'attendance_test',
/incorrect syntax
if(@$FORM['where'] == 'a'){'where' => " male = '$where' ",}
));
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php