0

Possible Duplicate:
MySQL query to sort upcoming birthdays based on current date

I have a MYSQL code like:

$friends=mysql_query("SELECT id,friend_id,f_name,
DATE_FORMAT(f_birthday,'%d %b')
AS f_birthday from friends where id='$id' 
ORDER BY MONTH(f_birthday), DAYOFMONTH(f_birthday)");

with this code block i can sort the user's birtdays with months and days starting from January first. But i can not sort them according to the upcoming birthdays. Searched for hours and found many solutions on stackoverflow but could not succeed. I really need help. Thanks.

EDIT

EXAMPLE OF MYSQL TABLE:

       id         friend_id        f_name      f_birthday
100001403795149 542542215       Mıchael        1984-10-01
100001403795149 557277949       MARY           1966-11-30
100001403795149 100002251590924 John           1985-07-05
100001403795149 100002534859304 Lucas          1977-09-15
Community
  • 1
  • 1
emerdog
  • 13
  • 4
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained and the [deprecation process](http://j.mp/Rj2iVR) has begun on it. See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – tereško Nov 02 '12 at 17:42

1 Answers1

0
SELECT id,friend_id,f_name,
DATE_FORMAT(f_birthday,'%d %b')
AS f_birthday from friends where id='$id' and f_birthday >=now()
ORDER BY MONTH(f_birthday), DAYOFMONTH(f_birthday) asc
AnandPhadke
  • 13,160
  • 5
  • 26
  • 33
  • Unfortunately not working. _MySQL returned an empty result_ – emerdog Oct 16 '12 at 14:57
  • This query will give you all birtdays which will fall today or in future in ascending order.So pls check in your table are there any records whoses birthday >=today – AnandPhadke Oct 16 '12 at 15:00
  • I have edited my question showing a few records of the database table. – emerdog Oct 16 '12 at 18:54
  • solved the problem by another question. Thanks. [http://stackoverflow.com/questions/7343807/mysql-query-to-sort-upcoming-birthdays-based-on-current-date] – emerdog Oct 16 '12 at 20:23