Re: newbie help
| From: | Dean Bennett | Date: | Sun, 25 Mar 2001 21:07:47 +0000 |
| Subject: | Re: newbie help | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7783@lists.php.net to get a copy of this message | ||
It looks like your checks are reversed, and you end up with 2 ANDs between the sex and height clauses. Like someone else pointed out, it is very helpful to echo the generated query so you can see what you've got.
A simpler solution, assuming that both fields are optional:
$sql = "SELECT ref, firstname, surname FROM $tablename";
$sql .= " WHERE 1=1";
if ($sex) // or if (!empty($sex)
$sql .= " AND sex = '$sex' ";
if ($heightFt)
$sql .= " AND heightFt = '$heightFt' ";
$sql .= " ORDER BY surname";
echo "query is $sql";
$result=@mysql_query($sql, $connection) or die ("bugger...!");