Jump to content

Need some help with creating price ranges from lowest and highest prices


matthew1471

Recommended Posts

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?

 

 

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.

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.