|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using PHP, SQL Question
I'm working on my site, and wondered if you knew the SQL command that displays
entries in the database from newest date to oldest? I am currenly using ORDER BY date, but this shows oldest to newest. IE: Dec 01 Dec 09 Dec 12 Code: $query = "SELECT *, date_format(concat(date,' 00:00:00'),'%b %d %y') AS date FROM $table WHERE activated = 1 ORDER BY date DESC"; $result = doQuery($query); |
|
#2
|
|||
|
|||
|
Try 'ORDER BY date ASC'
|
|
#3
|
|||
|
|||
|
Nope
Quote:
I tried this, but it didn't work. |
|
#4
|
|||
|
|||
|
I think you need ORDER BY date DESC.
-KM- |
|
#5
|
|||
|
|||
|
Quote:
Hi KM, that's what I did at first, use DESC, but this didn't work. |
|
#6
|
|||
|
|||
|
This is a pretty random guess (and I probably shouldn't even be speaking in my current condition, so take it as such), but try running your concat first:
concat(date_format(date,'%b %d %y'),' 00:00:00') It's possible that trying to format after adding the 0's may be throwing off the order. |
|
#7
|
|||
|
|||
|
Closer
Okay, so, we're getting closer!
This works, in the sense that it looks like: Dec 20 Dec 19 Dec 18 However, now November is at the top: Nov 20 Nov 19 Dec 20 Dec 19 Do you know how I can fiddle with the code so that December can be displayed first? And even so that November doesn't show up at all. Thanks! |
|
#8
|
|||
|
|||
|
SQL Query
How is your date set up in your database. Is it set up where the date is one field(how it is most of the time) or it set up where each part of the date is in its own field i.e. month filed, day field, year field? If it is set up in the prior form, what format is it in, numerical(12-1-04) or lexical(DEC 12 2004)? I am assuming that it is in the numerical format considering that you are performing the date_format() transformation. What you will want to try is to query the database and sort it by the numerical values, and then perform a date_format() transformation as you print out the data.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Using PHP, SQL Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|