Drop Shadow

Restricting rows

Often, you only display rows that match some criteria that has been sent via a form.

<? $searchFields = array('name', 'subject'); $db->where($searchFields); $db->display(); ?>

This will set all displays—whether display() or displayForm()—to only show those rows in the table that match whatever the viewer entered in the form fields called ‘name’ and ‘subject’.

If you have your own things you want to restrict the search on that were not entered in the form, you can add them also, but you’ll need to specify both the field name and the value that you’re looking for:

<? $searchFields = array('name', 'subject'); $searchRestrictions = array('city'=>'San Diego'); $db->where($searchFields, $searchRestrictions); $db->display(); ?>

Adding restrictions

Sometimes, it will be easier for you to see what your script does if you add your custom restrictions a piece at a time. You can use addRestriction() in addition to or in place of the second field list of where().

<? $searchRestrictions = array('user'=>$authenticatedUser); $db->addRestriction($searchRestrictions); ?>

If you need the restriction to apply to a join, then give the table of the restriction as a second parameter.

<? $searchRestrictions = array('user'=>$authenticatedUser); $db->addRestriction($searchRestrictions, 'accounts'); ?>

Kinds of restrictions

You can also specify what kind of a restriction your custom restrictions are.

<? $searchFields = array('name', 'subject'); $searchRestrictions = array('department'=>array('operator'=>'not', 'value'=>'Student'); $db->where($searchFields, $searchRestrictions); ?>

Currently, you can use the operators “not”, “is”, “before”, and “after”.

If you need to specify NULL, set the value to “null”. For example, “array('sent'=>null)”.