在SQL查询中需要很少的修改

Following is my sql query in which to facility_id i wat to assign value that comes from $fid. Kindly let me know what is wrong with the following code so i can remove them accordingly

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

Kindly try this:

$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";

small typo mistake add space between fid and group as following:

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

and next suggestion: no need to enclose $fid with double quote "

Here i have assumed your field facility_id is integer type. if its string then add double quotes "" to it like:

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