Re: ORDER BY Query
| From: | David Robley | Date: | Fri, 05 Sep 2003 12:43:39 +0000 |
| Subject: | Re: ORDER BY Query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-30349@lists.php.net to get a copy of this message | ||
In article <20030905122903.54348.qmail@pb1.pair.com>, shaun@mania.plus.com
says...
> Hi,
>
> I have a table in my database called Users. This table has (among others)
> two columns called Location and Name. Location will be either 1, 2, 3, or 4.
> How can I produce a query that groups the result into Location and then for
> each Location order the User by Name?
>
> Thanks for your help.
You'll need to mix a bit of php with your sql to get the desired result.
SELECT * FROM Users WHERE whatever ORDER BY Location, Name
Then when you display the results, initialise a variable to keep track of
the last value of Location. If it differs from the current value, display
the location. This way you end up with something like:
Location: 1
Bill
Fred
George
Location: 2
John
Agatha
Mercedes
etc etc
--
Quod subigo farinam
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?