Hi, i'm pretty new to this PHP stuff and need a bit of help with searching in PHP.
I've typed the actual query straight into MySQL and I get exactly what i'm looking for but when I try to output it, I get the same result multiple times. I've put my coding below.
I allow people to search using two criteria - city and interests. Problem is, if they leave city blank ("if" poriton of if-else statement), it brings up nothing everytime. However, if they enter in the city and interests ("else" portion), they get everyone in the database - not once, but three times. Probably because they all share EITHER the same activity OR city but not both.
I've got my query below and I suspect something is wrong there. I'll also add my printing loop below too.
**** IF ELSE QUERY *******
if (CCity == "CNone")
{
//Use this query when city NOT specified
$query = "SELECT CFirstName, CLastName, CCity, CEmail, CID
FROM clients, interests
WHERE (I1 = '$Interests' OR I2 = '$Interests' OR I3 = '$Interests' OR I4 = '$Interests' OR I5 = '$Interests' OR I6 = '$Interests' OR I7 = '$Interests')
ORDER BY CCity, CLastName";
}
else
{
//Use this query when city IS specified
$query = "SELECT CFirstName, CLastName, CCity, CEmail, CID
FROM clients,interests
WHERE ((I1 = '$Interests' OR I2 = '$Interests' OR I3 = '$Interests' OR I4 = '$Interests' OR I5 = '$Interests' OR I6 = '$Interests' OR I7 = '$Interests')
AND (CCity = '$CCity'))
ORDER BY CCity, CLastName";
}
****** PRINTING LOOP ******
(NOTE: num_rows is the total number of rows from my mysql_num_rows query - not shown here).
for ($loopvar=0; $loopvar<$num_rows; $loopvar++)
{
//This queries others with the same interests
$row = mysql_fetch_object($result);
$tempvar = $loopvar+1;
print "<tr>";
print " <TD>$tempvar</td>
<TD>$row->CFirstName $row->CLastName</td>
<TD>$row->CEmail</td>
<TD>$row->CCity</td>
<TD>
<font size=-1>
<B>
Add to my buddy list
</b>
</font>
</td>
<TD>$row->CID</td>";
print "</tr>";
}
print "</table>";