Jump to content

Help with Search Script


joalmoore

Recommended Posts

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.