以下是我的sql查询,其中来自facility_id我要分配来自$ fid的值。请让我知道以下代码有什么问题,以便我可以相应删除它们
$fid = 101;
$q = 'select r_present,r_reminder
from z_events
where resident_id = ?
and r_added > date_sub(curdate(), interval 37 day)
and fascility_id='."$fid". '
group by r_added
order by r_added
desc limit 4';
答案 0 :(得分:4)
小错字错误在fid和group之间添加空格如下:
$q = 'select r_present,r_reminder
from z_events
where resident_id = ?
and r_added > date_sub(curdate(), interval 37 day)
and fascility_id='.$fid. '
group by r_added
order by r_added
desc limit 4';
和下一个建议:无需用双引号"
这里我假设你的字段facility_id是整数类型。如果它的字符串然后添加双引号""
,如:
$q = 'select r_present,r_reminder
from z_events
where resident_id = ?
and r_added > date_sub(curdate(), interval 37 day)
and fascility_id="'.$fid. '"
group by r_added
order by r_added
desc limit 4';
答案 1 :(得分:1)
请试试这个:
$fid = 101;
$q = "select r_present,r_reminder from z_events where resident_id = ? and r_added > date_sub(curdate(), interval 37 day) and fascility_id=$fid group by r_added order by r_added desc limit 4";