Query String Filter from Drop-Down Menus
12 posts by 2 authors in: Forums > CMS Builder
Last Post: December 1, 2014 (RSS)
By claire - December 1, 2014
Okay, I see what you're trying to do here.
Check this out:
$where = "tableName = 'pages' AND fieldName ='gallery'";
if (@$_REQUEST['user'] != "") {
$where .= " AND info5 = ".mysql_escape($_REQUEST['user']);
}
if (@$_REQUEST['category'] != "") {
$where .= " AND info4 = ".mysql_escape($_REQUEST['category']);
}
// do getRecords here
The period followed by equals on $where indicates that the following string is to be appended to the end of $where, instead of replacing it entirely. Much easier than trying out a dozen different if statements, as it builds the $where parameter dynamically.
Also - ALWAYS escape your raw inputs. SQL injection is serious business!
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/