Re: Still needing help with dynamic queries
| From: | Richard Lynch | Date: | Fri, 01 Dec 2000 02:02:12 +0000 |
| Subject: | Re: Still needing help with dynamic queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28156@lists.php.net to get a copy of this message | ||
> stores about 15 pieces of info about each person. On the form (
> http://www.politics2004.com/personals/search.html ) you have 6
> options to
> search by, leaving all blank will return all results in the DB. At the
> bottom I have a check box that will make it search for all the criteria,
> while not checking it will return those with partial matches, as well.
<HTML><BODY>
<FORM ACTION=whatever.php METHOD=POST>
<INPUT NAME=key[sex]><BR>
<INPUT NAME=key[city]><BR>
<INPUT NAME=key[state]><BR>
<INPUT NAME=key[orientation]><BR>
<INPUT NAME=key[status]><BR>
<INPUT NAME=key[race]><BR>
<INPUT NAME=key[option]><BR>
<INPUT TYPE=RADIO NAME=strict VALUE=and> Strict <INPUT TYPE=RADIO
NAME=strict VALUE=or> Loose<BR>
<INPUT TYPE=SUBMIT NAME=submit VALUE=Search>
</FORM>
<?php
if (isset($submit)){
$query = "select * from personals where ";
if ($strict=='and') $query .= " 1=1 "
else $query .= " 1=0 ";
while (list($field, $value) = each($key)){
$query .= $strict . " $field = '$value' ";
}
}
echo $query, "<BR>\n";
$matches = mysql_query($query);
echo "<TABLE>\n";
while (list($sex, $name, $age...) = mysql_fetch_row($matches)){
echo
"<TR><TD>$sex</TD><TD>$name</TD><TD>$age</TD><TD>...</TD></TR>\n";
}
echo "</TABLE>\n";
?>
</BODY></HTML>