Re: ordering output
| From: | CPT John W. Holmes | Date: | Wed, 10 Dec 2003 22:19:21 +0000 |
| Subject: | Re: ordering output | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-31973@lists.php.net to get a copy of this message | ||
From: "redhat" <redhat@fayelectric.com>
> I have a page that I put together that pulls in data for the time in
> individual fields - hour, minute, am/pm, month, day. I am going to
> alter the db to add year as well. I want to order this list by multiple
> criteria - first by year, then by hour, am/pm, minute. It is a page
> that lists shows that are running on a local cable channel. Is there a
> way to do what I am asking? I know that I can 'select * from table
> order by year asc' but don't know how to sub order the items.
> thanks,
Answer you're looking for:
SELECT * FROM Table ORDER BY year ASC, month ASC, day ASC
Correct answer:
Use a DATETIME or TIMESTAMP field for your dates instead of separate columns
for each part. When you start looking for things that span certain lengths
of time, you'll thank yourself. You can still pull each part out if need be.
You'll also only need to sort based upon the single column.
---John Holmes...