What I would like to do is search a MySQL table for anywhere from one to 12 seprate fields, depending on what is submitted from a search form(has 12 different things that a user can search -- its an "AND" search only)
What I am unsure of is how to write the php code for multiple(possible combinations of) terms without having huge amount of lines of code to account for every combination.
my first thoughts are to add if statements, like this:
if (isset($fname)) { $sql_fname = " `fname` == '$fname'" ; } else { $sql_fname = ""; }
And then add to the query, like this:
$query = "SELECT * FROM tblsearch WHERE ".$sql_fname." && <and_so_on___more_search_terms_will_be_here>";
so that if the particular field isn't "POST"ed, then it is defined as "" and won't show up in the query.
My question is simply how the heck can I add the "&&" without knowing which fields the user will use in a search?
ALSO - does anyone know of a "grid" type script where I can just load the table into and filter the(multiple "AND"s) search terms via ajax?
Thanks!