ukweb Posted October 2, 2009 Share Posted October 2, 2009 Hi All I am making a site for a client, which sells motorbikes (see http://ktm-offroad.route55motorcycles.com/?file=vehicle_search On one side I am making a 'narrow results' section which will, obviously narrow down the number of bikes returned. I am making a filter for maximum price. The maximum price obviously changes depending on the stock being held, so I want the drop down box to list options at equal intevals from the price of the most expensive bike down to say £1000. For example, if the most expensive bike on record is £12,041 The system makes the max price selectable as £12,500 Then for every £500 inteval outputs '<option value=$value>.... Stops when £1000 is reached in psudo code this is how I am planning to do this, I'm sure if this is the best way, any ideas welcome [*]Run query and return the highest value bike [*]Round the value up to nearest £500 [*]Run for loop which outputs an option tag for that value, deduct 500 [*]Stop at £1000 Any ideas anyone? am I approaching this from the right angle? Quote Link to comment https://forums.phpfreaks.com/topic/176304-solved-simpler-way-of-doing-this/ Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 Sounds ok to me. Trying to think of something else to say... Hmm... Seen plenty of sites that seem to be working on a similar premis. Quote Link to comment https://forums.phpfreaks.com/topic/176304-solved-simpler-way-of-doing-this/#findComment-929188 Share on other sites More sharing options...
Adam Posted October 2, 2009 Share Posted October 2, 2009 Here's an example: <?php $max_price = 11215; $cur_price = ceil($max_price / 500) * 500; while ($cur_price >= 1000) { echo $cur_price . '<br />'; $cur_price = $cur_price - 500; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176304-solved-simpler-way-of-doing-this/#findComment-929191 Share on other sites More sharing options...
ukweb Posted October 2, 2009 Author Share Posted October 2, 2009 Here's an example: <?php $max_price = 11215; $cur_price = ceil($max_price / 500) * 500; while ($cur_price >= 1000) { echo $cur_price . '<br />'; $cur_price = $cur_price - 500; } ?> Nice one, never come across the ceil function before! Quote Link to comment https://forums.phpfreaks.com/topic/176304-solved-simpler-way-of-doing-this/#findComment-929197 Share on other sites More sharing options...
RussellReal Posted October 2, 2009 Share Posted October 2, 2009 <?php // way 1 function formulateDropDown($m) { $arr = array($num = 0); while ($m > ($num += 500)) $arr[] = $num; return $arr; } $s = mysql_query("SELECT MAX(price) As max, id, name, description FROM products"); $loop = 0; while ($r = mysql_fetch_assoc($s)) { if ($loop = 0) { $drop = formulateDropDown($r['max']); $loop++; } // do whatever with your results. } ?> <?php // way 2 function formulateDropDown($m) { $arr = array($num = 0); while ($m > ($num += 500)) $arr[] = $num; return $arr; } $s = mysql_query("SELECT MAX(price) As max FROM products LIMIT 1"); $drop = mysql_result($s,0); $s2 = mysql_query("SELECT * FROM products"); while ($r = mysql_fetch_assoc($s2)) { // do whatever with your results. } ?> not sure which was is faster Quote Link to comment https://forums.phpfreaks.com/topic/176304-solved-simpler-way-of-doing-this/#findComment-929199 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.