I have a page where people in a site selects search items.its a dating site.
so there is this first drop down menu for gender which u select three options:thus looking for
(all,Men,female) and another drop menu you select country which has two options:thus Country(all,.name of all the countries).
Men i denoted by symbol P and Female K and they are all served in a column Gender.
also countries are served in a column country in mysql database in table known as login.
I tried the code below for searching as illustrated above but it does not work.
Please i need your Help,Where i`m i getting wrong or which is the best way of doing this??
<?php
include"config.php";
$gender=$_POST['gender'];
$sercountry=$_POST['country'];
trim($gender);
trim($sercountry);
if(!$sercountry||!$gender){
echo "<font color=brown><b>You have not entered ALL search details.<b></font></br>
<font color=Brown><b>Please go back and
try again</b></font>";
exit;
}
if($gender==all||$sercountry==all){
echo"$gender $sercountry<br>";
$query="SELECT *FROM login ";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?wewe=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?wewe=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
if($gender ==all||$sercountry!==all){
echo"$gender $sercountry<br>";
$query="SELECT FROM login where country like '%$sercountry%'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
exit();
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?id=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?prof=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
if($gender==p||$sercountry==all){
echo"$gender $sercountry";
$query="SELECT FROM login where gender='p'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
exit();
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?id=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?prof=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
if($gender==p||$sercountry!==all){
echo"$gender $sercountry";
$query="SELECT FROM login where gender='p' and country like '%$sercountry%'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
exit();
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?id=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?prof=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
if($gender==k||$sercountry==all){
echo"$gender $sercountry";
$query="SELECT FROM login where gender='k'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
exit();
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?id=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?prof=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
if($gender==k||$sercountry!==all){
echo"$gender $sercountry";
$query="SELECT FROM login where gender='k' and country like '%$sercountry%'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if($num_results==0){
echo"<font color=maroon><b>No matches for your search.<br> specify category</b><br> <a href=index.php><< BACK</a></font>";
exit();
}
if($result){
while($row=mysql_fetch_array($result)) {
$userid=$row['id'];
$name=$row['name'];
$user=$row['user'];
$family=$row['family'];
$country=$row['country'];
$date=$row['date'];
$gender=$row['gender'];
echo "<table width=540 height=20 border=1 bordercolor=cyan cellpadding=5 cellspacing=2 align=center bgcolor=aliceblue>";
echo"<tr><td width=10%><p><a href= profile.php?id=$userid><img src=retrieve.php?id=$userid width=200 height=150 border=0></a></p></td><td width=30%><p>NAME:<font color=blue><a href= profile.php?prof=$userid> $name</a></font></p>
<p>FAMILY: <font color=blue>$family</font></p><p>COUNTRY:<font color=blue>$country</font></p><p>GENDER: <font color=blue>$gender</font></p>
<p>USER: <font color=blue>$user</font></p></td></tr>";
echo "</table>";
}
}
exit();
}
?>