可能重复:
MySQL query to sort upcoming birthdays based on current date
我有一个MYSQL代码,如:
$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)");
使用此代码块,我可以从1月1日开始按月和日对用户的生日进行排序。但我不能根据即将到来的生日对它们进行排序。搜索了几个小时,在stackoverflow上找到了许多解决方案,但无法成功。我真的需要帮助。 感谢。
修改
MYSQL表的例子:
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
答案 0 :(得分: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