Jump to content

Need help with PHP/MySQL drop down menu


Falanas

Recommended Posts

I need help on how I can implement a drop down menu which queries mysql database and output the available data based on price range. This feature has been used here http://www.vebra.com - I will appreciate your help.

 

$searchSQL = "SELECT  * FROM simple_search WHERE";

     

             

      // grab the search types.

      $types = array();

      $types[] = isset($_GET['price'])?"`price` LIKE '%{$searchTermDB}%'":'';

      $types[] = isset($_GET['location'])?"`location` LIKE '%{$searchTermDB}%'":'';

 

$types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)

     

      if (count($types) < 1)

        $types[] = "`id` LIKE '%{$searchTermDB}%'"; // use the estate as a default search if none are checked

 

 

$andOr = isset($_GET['matchall'])?'AND':'OR';

      $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `price`"; // order by price.

 

      $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");

     

      if (mysql_num_rows($searchResult) < 1) {

        $error[] = "The search term provided <i>{$searchTerms}</i> yielded no results.";

      }else {

 

          $results = array(); // the result array

        $i = 1;

        while ($row = mysql_fetch_assoc($searchResult)) {

            $results[] = "{$row['location']} <br/>{$row['image']}<br/>{$row['price']}";

 

$i++;

Link to comment
Share on other sites

for the price use BETWEEN

i.e.

you'd have priceMin and priceMax on the form.

$priceMin = isset($_GET['priceMin']) ? $_GET['priceMin'] : 0;

if (isset($_GET['priceMax'])) {
      $types[] = isset($_GET['price'])?"`price` BETWEEN $priceMin AND $priceMax":'';
} else {
      $types[] = isset($_GET['price'])?"`price` >= $priceMin":'';
}

 

is the script working at present?!

I don't get exactly what you want us to do...?

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.