DISPLAYING ONLY CERTAIN CATEGORIES AND/OR ALPHABETICAL LIMITATIONS - Aug 27th, 2010


I had an Artist’s membership database and I wanted to allow searches for specific categories of artists (disciplines)
or limit a search to particular alphabetical criteria.

The disciplines field contained a V" for Visual Artists, "M" for Media Artists, "P" for Performance Artists, "L" for
Literary Artists

Here’s the link code:



http://www.mysite.com/visualartists.php?sort_discipline=V



Which works to search for visual artists when combined with the code at the head of the visualartists.php web page



<?PHP
require_once "/hsphere/local/home/web/mysite.com/cmsAdmin/lib/viewer_functions.php";

list(
$artistsRecords, $artistsMetaData) = getRecords(array(
'Table name' => 'artists',
// Insert This Code
'where' => "discipline_code LIKE '%" .mysql_real_escape_string(@$_REQUEST['sort_discipline']). "%'",
// End of Insert
));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>



Of course you’ll have to replace the path information with your own.

NOTE: The word "sort" is not necessary in the link code or $_REQUEST, it's just a visual indicator that you are sorting
by a specific criteria. the request can be anything as long as you're consistent.

If you need to meet multiple parameters, then you could change the link to:



http://www.mysite.com/visualartists.php?sort_letter=A&sort_discipline=V



An extra % after LIKE will match the occurrence of that letter anywhere in the field:



'where' => "last_name LIKE '%" .mysql_real_escape_string(@$_REQUEST['sort_discipline']). "%'",
'where' => "last_name LIKE '%" .mysql_real_escape_string(@$_REQUEST['sort_letter']). "%' AND discipline_code = '"
.mysql_real_escape_string(@$_REQUEST['sort_discipline']). "'",



This format will match the first letter of the fields only...



'where' => "last_name LIKE '" .mysql_real_escape_string(@$_REQUEST['sort_discipline']). "%'",



or



'where' => "last_name LIKE '" .mysql_real_escape_string(@$_REQUEST['sort_letter']). "%' AND discipline_code = '"
.mysql_real_escape_string(@$_REQUEST['sort_discipline']). "'",



For a message regarding no members found, you could add:



<?PHP if (!$artistsRecords): ?>
<div class="body-text-bold" align="center"><?PHP echo
"Sorry, but no active members were found who match this category.<br /><br />"; ?>
<?PHP endif ?><div>






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