matthew1471 Posted July 7, 2008 Share Posted July 7, 2008 Hi all I'm trying to add a "Refine search: look at items in price range: £0 - £20, £20 - £30, £30 - £40" section the search results section of my price comparison website. The range of prices would be dependant on the lowest and highest prices returned in the user search (to stop a range of £1500 - £2000 showing for a search with a highest price of £200). For example, a search returning a lowest price of £102 and a highest of £230 would show the price ranges of 100 - 150, 150 - 200, 200 - 250. I would hardcode the ranges to be 0-20,20-40,40-60,70-80 etc etc. I've come to a complete road block, writers block, coders block on how to start the code to achieve this. Can anyone point me in the right direction? Link to comment https://forums.phpfreaks.com/topic/113585-need-some-help-with-creating-price-ranges-from-lowest-and-highest-prices/ Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 You can start by rounding the min and the max to the start and end ranges. If you wanted ranges of 50, you can round to the nearest 50 like this: $n = (round(($n/100)*2)/2)*100; Then it is just a matter of incrementing by your interval, echo $n . " - " . ($n+50); and querying: "SELECT * FROM Table WHERE Price > $n AND Price < ".($n+50) You can just pass the lowest value when user chooses a range. Link to comment https://forums.phpfreaks.com/topic/113585-need-some-help-with-creating-price-ranges-from-lowest-and-highest-prices/#findComment-583613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.