1

以下是我的 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';
4

2 回答 2

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';

和下一个建议:不需要用双引号括起来 $fid"

在这里,我假设您的字段 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';
于 2012-05-25T06:26:12.173 回答
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";
于 2012-05-25T06:28:29.363 回答