我正在尝试设置一个查询,根据我表中的年龄显示我网站上所有 25 岁以下的用户ptb_stats.user_age
。我设置了 -25 年的间隔,但它没有按我预期的方式工作。我究竟做错了什么?
我的功能:
function categories_agegroup_under25() {
global $connection;
$query = "SELECT *
FROM ptb_users, ptb_stats
WHERE ptb_users.account_type = \"User\" AND ptb_users.account_status = \"Active\" AND ptb_stats.user_id = ptb_users.id
AND ptb_stats.userage >= ADDDATE(CURRENT_DATE(), INTERVAL -25 YEAR)
ORDER BY ptb_stats.user_age DESC
LIMIT 0,40";
$categories_under25_set = mysql_query($query, $connection);
confirm_query($categories_under25_set);
return $categories_under25_set;
}
我的PHP:
<?php
$dob = $age['user_age'];
function age_from_dob($dob) {
$date = date_diff(date_create($dob), date_create('now'))->y;
return $date;
}
?>
<?php
$categories_under25_set = categories_agegroup_under25();
while ($age = mysql_fetch_array($categories_under25_set)) {
$date = age_from_dob($age['user_age']);
echo"
<div class=\"boxgrid caption\">
<a href=\"profile.php?id={$age['id']}\"><img width=140px height= 180px src=\"data/photos/{$age['id']}/_default.jpg\"/></a>
<div class=\"cover boxcaption\">
<h58> {$age['display_name']}, ".$date."</h58>
</div>
</div>";
}
?>