# shop by price

**URL:** <https://www.phphelp.com/t/shop-by-price/17658>\
**Category:** General Database (Oracle, SQL Server, etc)\
**Created:** [July 12, 2012, 8:53am UTC](https://www.phphelp.com/t/shop-by-price/17658 "2012-07-12T08:53:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://www.phphelp.com/uploads/default/original/2X/2/243e9ed5d93c5653ce3186f18df16e019ce38445.png) [@system](https://www.phphelp.com/u/system)\
**Post date:** [July 12, 2012, 8:53am UTC](https://www.phphelp.com/t/shop-by-price/17658/1 "2012-07-12T08:53:29Z")

</div>

Hello  
On my website, I would like to have a shop by price, something like the following

£0.01 - £2.99  
£2.99 - £3.99  
£3.99 - 6.99  
£6.99 - £9.99  
£9.99 or more

How would I do that and get the results from the mysql database when click on one of the above price links

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [July 12, 2012, 3:43pm UTC](https://www.phphelp.com/t/shop-by-price/17658/2 "2012-07-12T15:43:46Z")

</div>

something like  
[php]$tmp = explode("-", $\_POST[‘price’]);  
$start = $t[0];  
$end = $t[1];  
$q = mysql\_query(“SELECT \* FROM table WHERE price BETWEEN ‘$start’ AND ‘$end’”);

if(mysql\_num\_rows != 0) {  
while($row = mysql\_fetch\_array($q)) {  
// display items here

}  
} else {  
echo “No items found with in that price range”;  
}[/php]

That script assumes that you’re using radio butttons for the price selection, if you’re going to use checkboxes, then you need use a loop to process each selection.

---

<div class="post-metadata">

**Author:** ![OpzMaster](https://www.phphelp.com/letter_avatar_proxy/v4/letter/o/a9adbd/32.png) [@OpzMaster](https://www.phphelp.com/u/OpzMaster)\
**Post date:** [July 15, 2012, 4:24am UTC](https://www.phphelp.com/t/shop-by-price/17658/3 "2012-07-15T04:24:09Z")

</div>

Hello,

Richei, your code needs to be fixed a little.

[php]$tmp = explode("-", $\_POST[‘price’]);  
$start = $tmp[0];  
$end = $tmp[1];[/php]

I think that this is what you meant; tell me if I’m wrong.

Cheers!

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [July 15, 2012, 5:23am UTC](https://www.phphelp.com/t/shop-by-price/17658/4 "2012-07-15T05:23:25Z")

</div>

yea, thats what ment, thanks. :🙂
