SunQuest
 
           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 May 25th, 2005, 08:42 AM
jacannon2 jacannon2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 2 jacannon2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 18 sec
Reputation Power: 0
How to? (Order birthday results)

I'm trying to create a list of upcoming birthdays in my family, but I can't seem to figure out how to order the query results the way I want them.

Instead of ordering them from January 1st to December 31st (which I've already figured out how to do), I want to order the results from the current day forward into the next year and then only display the top five.

Here's an example of what I want the results to look like...
-------------------------------------
Happy Birthday Mark!

Bob turns 20
on June 6

Emily turns 23
on June 7

Fred turns 60
on August 23

Josephine turns 13
on September 31
-------------------------------------

I want the top result to say "Happy Birthday Whoever" only if it's that person's birthday on the day that the database is queried. After that day it should go back to "Whoever turns (age) on (date)" until their birthday comes up.

A similar question was asked on this forum and answered back in '03, but the only difference is I'm wanting to have each person's birthdate (year included). That way I can say how old they are. It would work if all the dates were with the same year, but that's not the case.

Any help would be greatly appreciated.

- JC2 <><

Reply With Quote
  #2  
Old May 25th, 2005, 09:07 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
Off the top of my head, and untested...

SELECT * FROM table WHERE birthday > NOW() ORDER BY birthday LIMIT 5

Reply With Quote
  #3  
Old May 25th, 2005, 11:01 AM
jacannon2 jacannon2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 2 jacannon2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 18 sec
Reputation Power: 0
But wouldn't that mess up because of the different birthyears?

If I have a birthday field with the "date" type, then each birthday will have a different year. I need some way to extract just the month and the day, then compare it with the current month and day of this year so that it will only display the next five birthdays from today on.

Reply With Quote
  #4  
Old May 25th, 2005, 04:06 PM
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:

Code:
    SELECT 
     foo 
    FROM
     table 
    ORDER BY 
     IF( DAYOFYEAR(birthday) >= DAYOFYEAR(CURDATE()),0,1),
     DAYOFYEAR(birthday) ASC
      LIMIT 5
   
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > How to? (Order birthday results)


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 1 hosted by Hostway