Question : MySQL php Select rows similar price

Hi,

Just a quick question I hope, I have a value 'price' from a row in my db. What I need to do is select three more random rows from the same table that have prices similar to the value I already have.

The problem I have is I cant think of an easy way to do this and I am sure there must be one.

Any help would really be appreciated

Thank you

Answer : MySQL php Select rows similar price

If you got access to PHP, you could do this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<?php
	mysql_connect("localhost","root","myPassword");
	mysql_select_db("itemDatabase");
	$price=120;
	
	$pricemin=$price-$price/10;
	$pricemax=$price+$price/10;
	echo $pricemin.$pricemax;
	$query=mysql_query("SELECT * FROM itemlist WHERE price<$pricemax AND price>$pricemin");
	while($row=mysql_fetch_array($query))
	{
		echo "$row[name] -$row[price]<br>";
	}
?>
Random Solutions  
 
programming4us programming4us