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:
  #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: 37 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 30 m 15 sec
Reputation Power: 6
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: 1,030 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: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1978056 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 1 Week 9 h 13 m 59 sec
Reputation Power: 7
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: 564

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: 5
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 14 m 9 sec
Reputation Power: 10
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: 37 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 30 m 15 sec
Reputation Power: 6
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: 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"


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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek