Can anyone can tell me what is wrong with this
$paramcari is the value that needs to be search for, it should be the data with the a.status not 0 and not 2 but the filter doesn’t work, the output always show all status whether it is 0 , 0 or 2… what did I miss?
$sql="select a.*, b.*, d.*, e.*, f.*, j.*, k.*, DATE_FORMAT(a.tgldaftar,'%d %b %Y %H:%i') as tgldaftar,
DATE_FORMAT(a.tglkeluar,'%d %b %Y %H:%i') as tglkeluar , i.*
from daftar a
INNER JOIN pasien b ON a.noRM=b.noRM
INNER JOIN ranjang d ON a.idranjang=d.idranjang
INNER JOIN ruang e ON d.idruang=e.idruang
INNER JOIN kelas j ON e.idkelas=j.idkelas
INNER JOIN instalasi k ON e.idinstalasi=k.idinstalasi
INNER JOIN (select idjenispasien , jenispasien from jenispasien ) f ON a.idjenispasien=f.idjenispasien
INNER JOIN rujukan i ON a.idrujukan=i.idrujukan and a.status !=0 and a.status != 2";
if($paramcari != ""){
$sql.=" and b.nama like '%$paramcari%' ";
$sql.=" or j.namakelas like '%$paramcari%' ";
$sql.=" or e.namaruang like '%$paramcari%' ";
$sql.=" or b.idRM like '%$paramcari%' ";
$sql.=" or i.namars like '%$paramcari%' ";
$sql.=" or a.nodaftar like '%$paramcari%' ";
}
$sql.="ORDER BY a.tgldaftar ASC limit $start,15 ";
Your search condition
and a.status !=0 and a.status != 2is appended to the last inner join condition. It should be in a where condition instead. Change the last join toAlso add braces to your search condition, because
andhas higher precedence thanor