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...!");

PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to