是的,这听起来很奇怪。
Yes, this may sound strange.
在高级个人资料搜索表单中,您可以按年龄进行过滤。
In the advanced profile searching form, where you can filter by age.
现在你可以在字段中输入18或其他年龄。
Now you would type 18 or some other age in the field.
我将生日存储在mysql db中的用户i的生日字段中例如:1990-02-02
I am storing the birthdays, in the mysql db, in the birthday field in users i have example: 1990-02-02
如何在查询中按年龄筛选?
How can i filter by age then, in a query?
如果我先做一个查询,让所有用户的生日达到年龄,然后比较他们?
Should i first make a query before, make all users birthdays to age, and then compare them? Would be too much, to take each one user.
推荐答案我打赌这是你正在寻找的:
I bet this is what you are searching for:
SELECT * FROM mytable WHERE TIMESTAMPDIFF(YEAR, mytable.birthday,'$currentTime') > '$ageFromForm';要对数据进行排序,请执行以下操作:
To sort the data you would perform this :
SELECT *, (TIMESTAMPDIFF(YEAR, mytable.birthday, '$currentTime')) AS age FROM mytable WHERE TIMESTAMPDIFF(YEAR,'$birthday','$currentTime') > '$ageFromForm' ORDER BY age;我希望这会有帮助;) Slavic
I hope this helps ;) Slavic
更多推荐
PHP:从年龄计算生日
发布评论