MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old October 11th, 2005, 07:42 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
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?

Reply With Quote
  #2  
Old October 12th, 2005, 12:56 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 956 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2Folding Points: 651767 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 8 h 23 m 32 sec
Reputation Power: 4
Send a message via ICQ to Itsacon
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.

Reply With Quote
  #3  
Old October 12th, 2005, 03:19 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
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

Reply With Quote
  #4  
Old October 12th, 2005, 07:21 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
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 !=''

Reply With Quote
  #5  
Old October 19th, 2005, 12:42 AM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
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.

Reply With Quote
  #6  
Old October 19th, 2005, 10:36 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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"


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Order by Date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway