Setting a “where” value from a form selection (revisit)

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 22, 2013   (RSS)

By gkornbluth - May 21, 2013

Hi All,

Sorry to have to revisit Post # 2216823 “Setting a “where” value from a form selection” (now archived), that Jason helped so much with,  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 checkbox 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 in that post, but the page always returns only those records where the value of the checkbox 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

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - May 22, 2013

Hi Greg,

I could swear I tried that, but I guess not :-(

Anyway, it works and thanks!

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php