-
mysql query in php
hi everyone,
i have a msyql database with 1 table (almost 2,000 records) for now. one of the fields of this table is 'cost'. i want a query that results, like the ff:
Cost
2,000 to 3,000
4,000 to 6,000
7,000 to 12,000
.
.
.
greater than 20,000
this is for my search option list. is it possible? a query that returns like this? maybe, except for the last one line.
any help really appreciated...
-
Re: mysql query in php
Not an expert.
But would imagine you can either do multiple SQL statements, apparently a bad thing, or use the "ORDER BY cost" to sort the records then use a switch statement to process them individually in php script.
-
Re: mysql query in php
So you want to select things, ONLY if they are a certain amout?
Try this (untested):
Code:
$sql = "SELECT * FROM `table` WHERE `price` >= 20000;";
$query = mysql_query($sql, $link)
or die("Error; " . mysql_error());
-
Re: mysql query in php
Code:
SELECT count(id), FLOOR(value/1000)*1000 calc FROM test1 GROUP BY calc;
SELECT value, FLOOR(value/1000)*1000 calc FROM test1 ORDER BY value;
A simple reduction function on the value can sort them out into any ranges you like. Just remember the calc column will contain the lower bound of your range and no value will appear for a range if there are no values within the range.