|
-
Feb 1st, 2008, 10:30 AM
#1
Thread Starter
Fanatic Member
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...
noister
<advertising link removed by moderator>
-
Feb 2nd, 2008, 09:31 PM
#2
Hyperactive Member
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.
-
Feb 6th, 2008, 08:48 AM
#3
New Member
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());
-
Feb 6th, 2008, 10:11 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|