ALLOWING VISITORS TO SET VIEWER ORDERBY OPTIONS IN A VIEWER - Sep 5th, 2022


A while back user rjbathgate wanted to enable visitors to determine the order that results are displayed in a viewer
from a series of options.

Dave Edis from Interactive Tools offered:

First create a search form on the viewer, something like:


<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

<select name="order">
<option value="a">price (highest first)</option>
<option value="b">price (lowest first)</option>
...etc...
</select>

<input type="submit" name="submit" value="Search">
</form>


Then add some code to the list records call at the top of the viewer code


$orderBy = "";
if (@$FORM['order'] == 'a') { $orderBy = "price DESC"; }
if (@$FORM['order'] == 'b') { $orderBy = "price"; }
# ... etc ...


list($your_tableRecords, $your_tableMetaData) = getRecords(array(
'tableName' => 'your_table',
'orderBy' => $orderBy,
));


NOTE: According to Dave Edis from Interactive Tools, the reason to do it that way by passing a letter (or word or code,
it doesn't matter) and testing for that instead of just specifying the order by in the option value directly is because
you don't want users to be able to pass MySQL directly into your program or it's a security risk.

You can expand this idea to create as complex a set of criteria as required.






The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service