anthony-needs-you Posted January 9, 2009 Share Posted January 9, 2009 hi everyone, i have a search with ranges its working fine except for the 'any ...' fields here is the html <span class="search-subhed">Holiday Type?</span><br /> <select name="breakType" class="field"> <option selected="selected">-- please select --</option> <option value="holidaybreaks">Holiday Breaks</option> <option value="cruises">Cruises</option> <option value="citybreaks">City Breaks</option> <option value="sporting">Sporting Holidays</option> <option value="flights">Flights</option> <option value="hotel">Hotel Bookings</option> </select><br /> <span class="search-subhed">Destination?</span><br /> <input name="where" type="text" value="" class="field" /><br /> <span class="search-subhed">Price?</span><br /> <select name="pricerange" class="field"> <option value="0:10000" selected="selected">Any price</option> <option value="0:500">£0-£500</option> <option value="501:1000">£501-£1000</option> <option value="1001:2000">£1001-£2000</option> <option value="2000:10000">Over £2000</option> </select><br /> <span class="search-subhed">Duration?</span><br /> <select name="stay" class="field"> <option value="1:42" selected="selected">Any duration</option> <option value="1:1">1 night</option> <option value="2:2">2 nights</option> <option value="3:3">3 nights</option> <option value="4:4">4 nights</option> <option value="5:5">5 nights</option> <option value="6:6">6 nights</option> <option value="7:7">7 nights</option> <option value="8:8">8 nights</option> <option value="9:9">9 nights</option> <option value="10:10">10 nights</option> <option value="12:12">12 nights</option> <option value="14:14">14 nights</option> <option value="21:21">21 nights</option> <option value="21:42">Over 21 nights</option> </select><br /> <input name="search" type="submit" id="search" value="Search" /> and here is part of the php if($breakType == 'holidaybreaks') { list($min,$max) = explode(':',$_POST['pricerange'],2); list($minstay,$maxstay) = explode(':',$_POST['stay'],2); $result = mysql_query("SELECT departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, description, customerRef, mystiqueRef, stars FROM holiday WHERE duration BETWEEN '$minstay' AND '$maxstay' AND price BETWEEN '$min' AND '$max' AND destination LIKE '%$where%'"); When 'any price' or 'any duration' is selected with a destination it shows no results? Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/ Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 can you echo the query when u have any selected? Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733344 Share on other sites More sharing options...
anthony-needs-you Posted January 9, 2009 Author Share Posted January 9, 2009 if i leave the destination field blank the any's will pull all of the holidays Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733356 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 can you echo the query when u have any selected? Can you do this? Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733358 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 if i leave the destination field blank the any's will pull all of the holidays Are you sure you have data for all 3 conditionals? If you do not have data that match all 3 you will not get anything returned. If you want to match any price, you keyed it in your last sentence on your first post "or" $result = mysql_query("SELECT departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, description, customerRef, mystiqueRef, stars FROM holiday WHERE duration BETWEEN '$minstay' AND '$maxstay' OR price BETWEEN '$min' AND '$max' OR destination LIKE '%$where%'"); That query uses the "OR" keyword instead of the "AND" which should pull results if ANY of those conditions are true. Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733360 Share on other sites More sharing options...
anthony-needs-you Posted January 9, 2009 Author Share Posted January 9, 2009 the problem i'm getting with that is if you type in a destination and leave the other fields to any it will pull all of the holidays from the table and not just the destination do you know why? Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733402 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 the problem i'm getting with that is if you type in a destination and leave the other fields to any it will pull all of the holidays from the table and not just the destination do you know why? You probably want to dynamically create the where clause. if (isset($_POST['pricerange']) && $_POST['pricerange'] != "0:10000") { list($min,$max) = explode(':',$_POST['pricerange'],2); $whereClause[] = " price BETWEEN '$min' AND '$max' "; } if (isset($_POST['stay'])) { list($minstay,$maxstay) = explode(':',$_POST['stay'],2); $whereClause[] = " duration BETWEEN '$minstay' AND '$maxstay' "; } if (isset($_POST['desination'])) { $whereClause[] = " destination LIKE '%$where%' "; } $whereClause = implode (" OR ", $whereClause); $result = mysql_query("SELECT departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, description, customerRef, mystiqueRef, stars FROM holiday WHERE $whereClause"); That way it only uses the values that have a value. Not sure if that is what you are looking for though, but yea. Quote Link to comment https://forums.phpfreaks.com/topic/140151-search/#findComment-733406 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.