Query Strings and the isset command
Posted: Fri Feb 25, 2011 8:38 pm
Hello All,
I have a question concerning how to write a query string that will allow a search on several form input boxes where any of the input boxes may be empty or null except one. (There always has to be at least a single search term.)
here is some of the code I have thus far:
You can view the current page Here
To recap: I want to be able to search on any single or a combination of the fields. As it is right now I can do a search on only Specialty and return results. I can search on Specialty and State and return results, but i can't search on only state, or only city, or only any of the other fields except Specialty, and return results.
I have been trying to do If ... Else statements and I have even tried isset statements but dont know how to use them very well so i failed. I think isset or if..else statments are the way to go though. So could someone assist me with a little idea on how to do this?
Thanks in advance to any and all support.
I have a question concerning how to write a query string that will allow a search on several form input boxes where any of the input boxes may be empty or null except one. (There always has to be at least a single search term.)
here is some of the code I have thus far:
Code: Select all
// variable string list
$lastname = $_POST['lastname'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$specialty = $_POST['specialty'];
// this is the query string section
$sql = mysql_query("select * from doctors where Specialty like '%$specialty%' and State like '%$state%' and City like '%$city%' ");
while ($row = mysql_fetch_array($sql)){
echo 'ID: '.$row['ID'];
echo '| Dr. '.$row['FirstName'];
echo ' '.$row['LastName'];
echo ', '.$row['City'];
echo ' '.$row['State'];
echo '. '.$row['Zip'];
echo ', '.$row['Specialty'];
echo ' ';
print( '<a href="http://www.cybersoapbox.net/bernard/sunday/new2/results.php"> Click Here For More Information</a>' );
echo '<br/><br/>';
}
To recap: I want to be able to search on any single or a combination of the fields. As it is right now I can do a search on only Specialty and return results. I can search on Specialty and State and return results, but i can't search on only state, or only city, or only any of the other fields except Specialty, and return results.
I have been trying to do If ... Else statements and I have even tried isset statements but dont know how to use them very well so i failed. I think isset or if..else statments are the way to go though. So could someone assist me with a little idea on how to do this?
Thanks in advance to any and all support.