Forum Moderators: open
I am trying to make a search page that will allow more than one variable to come into play when searching for records. Currently, the below script only supports one variable to be passed ("q"). i want to set it up so that it will display records that meet 2 variables criteria..example...First name and Last name....
The call for the variable ($var = @$_GET['q'];) gets the term searched for from the input box with name "q"....How would i set it up so that it will accept multiple variables and return search results based on both criteria....THANKS!
<body>
<form name="form" action="search.php" method="get">
<input type="text" name="q" />
<input type="text" name="z" />
<input type="submit" name="Submit" value="Search" />
</form>
<table width="630" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top"><?php
$var = @$_GET['q'];
$trimmed = trim($var); //trim whitespace from the stored variable
$s = trim(@$_GET['s']);
// rows to return
$query = "select * from $table
where $col like \"%$trimmed%\"
or $col2 like \"%$trimmed%\"
or $col3 like \"%$trimmed%\"
or $col4 like \"%$trimmed%\"
or $col5 like \"%$trimmed%\"
or $col6 like \"%$trimmed%\"
or $col7 like \"%$trimmed%\"
or $col8 like \"%$trimmed%\"
or $col9 like \"%$trimmed%\"
or $cola like \"%$trimmed%\"
or $colb like \"%$trimmed%\"
or $colc like \"%$trimmed%\"
or $cold like \"%$trimmed%\"
or $cole like \"%$trimmed%\"
or $colf like \"%$trimmed%\"
or $colg like \"%$trimmed%\"
or $colh like \"%$trimmed%\"
or $coli like \"%$trimmed%\"
or $colj like \"%$trimmed%\"
or $colk like \"%$trimmed%\"
or $coll like \"%$trimmed%\"
or $colm like \"%$trimmed%\"
or $coln like \"%$trimmed%\"
or $colo like \"%$trimmed%\"
or $colp like \"%$trimmed%\"
or $colq like \"%$trimmed%\"
or $colr like \"%$trimmed%\"
order by $sorted";
[edited by: txbakers at 2:05 am (utc) on Jan. 3, 2007]
[edit reason] eliminated unnecessary code [/edit]
$var = @$_GET['q'];
$trimmed = trim($var); //trim whitespace from the stored variable$varZ = @$_GET['z'];
$trimmedZ = trim($varZ);
then, modify your query to search on the "trimmedZ" value as well:
WHERE $col like \"%$trimmed%\"
or $col2 like \"%$trimmed%\"
or $col3 like \"%$trimmed%\"
or $col4 like \"%$trimmed%\"
or $col5 like \"%$trimmed%\"
or$col like \"%$trimmedZ%\"
or $col2 like \"%$trimmedZ%\"
or $col3 like \"%$trimmedZ%\"
or $col4 like \"%$trimmedZ%\"
or $col5 like \"%$trimmed%\"
that's all there is to it.