Jump to content

price range searches


anthony-needs-you

Recommended Posts

Hi i was hoping that someone maybe able to tell me how to code a price range drop down search menu. I am unsure as to what to enter as the option value:

 

<span class="search-subhed">Where?</span><br />
        <input name="where" type="text" value="Enter keywords / Hotel Name" class="field" /><br />
        <span class="search-subhed">Price?</span><br />
        <select name="price" class="field">
          <option selected="selected">any price</option>
          <option>£0 - £100</option>
          <option>£101 - £300</option>
          <option>£301 - £500</option>
        </select><br />
        <span class="search-subhed">Duration?</span><br />
        <select name="duration" class="field">
          <option selected="selected">any duration</option>
          <option value="1">1 night</option>
          <option value="2">2 nights</option>
          <option value="5">5 nights</option>
          <option value="6">6 nights</option>
          <option value="7">7 nights</option>
          <option value="10">10 nights</option>
          <option value="14">14 nights</option>
        </select>

 

here is the php i am planning to use:

select * from holiday where price between 0 and 100

Link to comment
Share on other sites

There's more than one way to skin a cat. You could set the values to things like "0 AND 100", "101 AND 300" and use them directly in your query (after using mysql_real_escape_string on them, of course). You could give them arbitrary values and use an if-else/switch statement or set the values to indexes in an array which contains the price ranges. Up to you really.

Link to comment
Share on other sites

<select name="price" class="field">
  <option selected="selected" value="">any price</option>
  <option value="0:100">£0 - £100</option>
  <option value="101:300">£101 - £300</option>
  <option value="301:500">£301 - £500</option>
</select>

 

<?php
  $sql = "select * from holiday";
  if($_POST['price']){
    list($min,$max) = explode(':',$_POST['price'],2);
    $sql .= sprintf(" WHERE price BETWEEN '%s' AND '%s'",mysql_real_escape_string($min),mysql_real_escape_string($max));
  }
  echo $sql;
?>

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.