PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP 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 December 20th, 2004, 09:48 AM
dayontheforce dayontheforce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 dayontheforce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);

Reply With Quote
  #2  
Old December 20th, 2004, 11:45 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
Try 'ORDER BY date ASC'

Reply With Quote
  #3  
Old December 20th, 2004, 04:48 PM
dayontheforce dayontheforce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 dayontheforce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Nope

Quote:
Originally Posted by Madpawn
Try 'ORDER BY date ASC'

I tried this, but it didn't work.

Reply With Quote
  #4  
Old December 20th, 2004, 05:19 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
I think you need ORDER BY date DESC.

-KM-

Reply With Quote
  #5  
Old December 21st, 2004, 10:00 AM
dayontheforce dayontheforce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 dayontheforce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by kode_monkey
I think you need ORDER BY date DESC.

-KM-

Hi KM,

that's what I did at first, use DESC, but this didn't work.

Reply With Quote
  #6  
Old December 21st, 2004, 10:13 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
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.

Reply With Quote
  #7  
Old December 23rd, 2004, 10:36 AM
dayontheforce dayontheforce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 dayontheforce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #8  
Old January 3rd, 2005, 10:38 AM
phpPrgrmmr phpPrgrmmr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 11 phpPrgrmmr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Using PHP, SQL Question


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
Stay green...Green IT