cary1234, on 10 Oct 2013 - 11:04 PM, said:
Hello! Right now I'm working on advance search for my website and I'm stuck on this part of my website. I'm glad I can shout for help here in you forums. :)
What I want is whenever a user use the advance search the user can search for first name, last name, middle name and lastly nick name.
The Condition:
Sometimes the user may want to define their search specifically like for example I want to search all the people who have a last name "Bondoc" that lives in "Philippines" so they will check the checkbox for first name and country then click the advance search. What is the best code for this logic?
Right now this is what I did.. But I guest I will code every type of combination which really needs some effort, any other idea please?
INPUT
THE RESULT
And here's my code
$db_Connection = mysqli_connect($db_Host, $db_User, $db_Pass, $db_Name);
$cb_Fname = $_POST['cb_Fname'];
$tb_Fname = $_POST['tb_Fname'];
$cb_Lname = $_POST['cb_Lname'];
$tb_Lname = $_POST['tb_Lname'];
if ($cb_Fname == "1"){
//checkbox is CHECKED
$fname = "fname LIKE '%$tb_Fname%'";
}
else{
//checkbox not CHECKED
$fname = "";
}
if ($cb_Lname == "1"){
//checkbox is CHECKED
$lname = "AND lname LIKE '%$tb_Lname%'";
}
else{
//checkbox not CHECKED
$lname = "";
}
$qry_Ftt = mysqli_query($db_Connection, "SELECT * FROM users WHERE $fname $lname");
?>