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
https://forums.phpfreaks.com/topic/139542-price-range-searches/
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
https://forums.phpfreaks.com/topic/139542-price-range-searches/#findComment-729930
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
https://forums.phpfreaks.com/topic/139542-price-range-searches/#findComment-729938
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.