|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Order by Date
My current querry string is:
$query="SELECT * FROM programs WHERE date != '' ORDER BY date DESC, progname ASC"; The output puts a date like 9/30 at the top of the list, then 8/30.... down to 1/1, then at the end is 10/10 Is there a way to get that 10/10 listing at the top, by either changing the querry, or the way the date is entered in the database field? |
|
#2
|
||||
|
||||
|
you could use a DATE field instead of a string to store the date. Sorting will then work properly.
And you get all kinds of nifty formatting and calculation options... See also this thread
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 264
![]() Last edited by Itsacon : October 12th, 2005 at 01:03 AM. |
|
#3
|
|||
|
|||
|
First, I hope your column for the date is DATE or DATETIME.
Secondly, I am not sure sure how well your string is going to work since you try to sort the results 2 times in one string. $query="SELECT * FROM programs WHERE date != '' ORDER BY date DESC, progname ASC"; Think you need to make a decision if you like to sort the results by date or progname. Your WHERE statement makes me confused, are you trying to make a list of results sorted by date in a specified period of time? If so, I would look into the BETWEEN statement. Not sure if I answered this correctly, perhaps I just made a bigger mess of things now ![]() |
|
#4
|
||||
|
||||
|
Laban:
sorting by two fields is fine. It's basically saying, when the dates are the same, sort by progname. mlmpros: You would have more control over your results if your date field were defined as DATE (or something similar). I would also use "NOT NULL" instead of !='' |
|
#5
|
|||
|
|||
|
Replied to these answers before, but it apparantly didn't take.
The field I am sorting is DATE. And it's all entries, not a particular range. It also makes no difference if the second sort is there or not. |
|
#6
|
|||
|
|||
|
If you're sorting by a DATE type field, it should be fine. Please post your table structure (you can run a SHOW CREATE TABLE command and paste the results), a few rows of sample data exactly as you have it in your table (though it doesn't have to be the exact data, of course, if you have stuff in there you'd rather not share with the internet), and your exact query.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn" |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Order by Date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|