Okay...this is different from what you've got, but after I saw what you were trying to do, give this a try...just add in your table names.
You can cut your sql query down to one by joining them together. Give it a go and let me know if it works. I'll explain anything if you need me to, also. This will also print out all of the matches, in case there are multiple. I assumed that would be possible.
<body>
<?php
//enter your table names here.
$dbtable2 = ??;
$dbtable4 = ??;
//create our criteria
if ($gender != "gender")
{ $criteria[0] = " db2.gender = '$gender' "; }
if ($figure != "figure")
{ $criteria[1] = " db2.figure = '$figure' "; }
if ($eyes != "eyes")
{ $criteria[2] = " db2.eyes = '$eyes' "; }
if ($hair != "hair")
{ $criteria[3] = " db2.hair = '$hair' "; }
if ($marital != "marital")
{ $criteria[4] = " db2.marital = '$marital' "; }
if ($religion != "religion")
{ $criteria[5] = " db2.religion = '$religion' "; }
if ($sexuality != "sexuality")
{ $criteria[6] = " db2.sexuality = '$sexuality' "; }
if ($state != "state")
{ $criteria[7] = " db2.state = '$state' "; }
//join together criteria with "and" if there are more than
//one of them.
if (count($criteria) > 1)
{
$final_criteria = " AND ( " . implode(" AND ",$criteria) . " ) ";
}
elseif (count($criteria) == 1)
{
$final_criteria = " AND ( " . $criteria[0] . " ) ";
}
//create sql command and echo to browser.
$sql = "SELECT db4.username FROM $dbtable2 as db2, $dbtable4 as db4 WHERE db2.id = db4.id $final_criteria";
echo "Query = $sql <BR>\n";
//issue query to mysql
$query = mysql_query($sql);
//include top header
include("top.inc");
//check and see if a row was returned...
if ($row = mysql_fetch_array($query))
{
//if row was returned, loop through the matches
do
{
echo "Match: " . $row["username"] . "<BR>\n";
} while ($row = mysql_fetch_array($query))
}
//else if no row was returned, echo message.
else
{
echo "No Match<BR>\n";
}
//include bottom part of page.
include("bottom.inc");
?>
</body>
---John Holmes...