joalmoore Posted June 24, 2012 Share Posted June 24, 2012 Hi, I'd like to get some help with my search script. A little about the site: I have registered users and when they register they select their user type (ie Nanny, Homecare, Daycare). Right now I have a search bar and visitors can input their zip code and the results page shows everything in the database with that zip code. Current form: <form id="form1" name="form1" method="get" action="results.php"> <p> <label>Search for<input type="text" name="Search" id="Search" /></label> <label> <select name="Field" id="Field"> <option value="Zip">Zip</option> </select> </label> <input type="submit" name="button" id="button" value="Search" /> </p> </form> What I would like to do is to have it where users enter their zip code and select Nanny, Homecare, or Daycare from a drop down and the results shows only that type in the search results instead on everything within that zip. How I want the form to look: <form id="form1" name="form1" method="get" action="results.php"> <p> <label>Search for<input type="text" name="Search" id="Search" value="Zip" /></label> <label> <select name="Field" id="Field"> <option value="Nanny">Nanny</option> <option value="Homecare">Homecare</option> <option value="Childcare">Childcare</option> </select> </label> <input type="submit" name="button" id="button" value="Search" /> </p> </form> The php: <?php require_once('scripts/_config.php'); if(isset($_GET['Field'])){ $searchQ1=mysql_query("SELECT `First_Name`,`Last_Name`,`Nanny`,`Homecare_Provider`,`Childcare_Center`,`City`,`State`,`Zip`,`userID` FROM `sys_profile` WHERE `".$_GET['Field']."` LIKE '".$_GET['Search']."';"); }else{ $searchQ1=mysql_query("SELECT `First_Name`,`Last_Name`,`Nanny`,`Homecare`,`Childcare`,`City`,`State`,`Zip`,`userID` FROM `sys_profile` WHERE `userID`!=0;"); } ?> How do I change the php so that the search results displays only nannies within the entered zip, or childcare in the entered zip, etc? Right now the php shows everything in that zip and when I change the form to the second example it still doesn't work because I'm not sure how to adjust the search query. Quote Link to comment https://forums.phpfreaks.com/topic/264693-help-with-search-script/ Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 You need a "type" field in the record which will contain either Nanny, Homecare or Childcare. the query is then SELECT .... WHERE zip = '$search' AND type = '$field' where $search and $field are from the form data Quote Link to comment https://forums.phpfreaks.com/topic/264693-help-with-search-script/#findComment-1356639 Share on other sites More sharing options...
joalmoore Posted June 24, 2012 Author Share Posted June 24, 2012 Thanks, I got it all worked out from another site. Quote Link to comment https://forums.phpfreaks.com/topic/264693-help-with-search-script/#findComment-1356641 Share on other sites More sharing options...
joalmoore Posted June 24, 2012 Author Share Posted June 24, 2012 not sure how to mark as solved, but its solved. In case someone else needs this kind of help here is what I needed in the php $searchQ1=mysql_query("SELECT `First_Name`,`Last_Name`,`Nanny`,`Homecare_Provider`,`Childcare_Center`,`City`,`State`,`Zip`,`userID` FROM `sys_profile` WHERE `Zip`=`".$_GET['Field']."` AND '".$_GET['Search']."'=true;) The form that I used is <form id="form1" name="form1" method="get" action="results.php"> <p> <label>Search for<input type="text" name="Search" id="Search" value="Zip" /></label> <label> <select name="Field" id="Field"> <option value="Nanny">Nanny</option> <option value="Homecare">Homecare</option> <option value="Childcare">Childcare</option> </select> </label> <input type="submit" name="button" id="button" value="Search" /> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/264693-help-with-search-script/#findComment-1356644 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 Which board did you get that solution from? I think we should warn others not to go there. Quote Link to comment https://forums.phpfreaks.com/topic/264693-help-with-search-script/#findComment-1356677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.