Here's what I have, and what I want to do:
I have 12 items in my MySql database. 4 products are 4.99, 4 products are 3.99 and 4 products are 2.99.
I realize I can query the database like this, and It will give me a list of products at that price:
$query = "SELECT * FROM UFPProducts WHERE price = 4.99";
$results = mysql_query ($query, $connect);
while ($row = @ mysql_fetch_array($results))
{
"
"
Product id ".$row["ProductID"]."
"."
"."
£".$row["Price"]."
"."
".$row["Description"]."
"."
}
?>
However, what I want, is a button I can press to sort products by price.
What's a simple way of doing this?
Thanks
解决方案
Try this query
$query = "SELECT * FROM UFPProducts order by price ASC";
The above query will list all price in ascending order. But if you want to have distinct price grouped together, use the below query.
$query = "SELECT * FROM UFPProducts group by price order by price ASC";