sql語句多條件查詢子查詢(總數量) 子查詢

多條件查詢

if (IS_POST) {

$search_pid = I('search_pid');

$search_cname = I('post.search_cname');

$hospitalid = I('post.hospitalid');

if ($search_pid != '') {

$where_arr[0]= " patientid = '$search_pid' ";

}

if($search_cname!=''){

$where_arr[1] = " cname like '%$search_cname%' ";

}

if($hospitalid!=""){

$where_arr[2] =" hospitalid ='$hospitalid' ";

}

$where = implode('and',$where_arr);

if(empty($where)){

$where = 1;

}

$p = I('post.p');

if($p==''){

$p = 0;

}else{

$p = ($p-1)*$num;

}

$Model = new \Think\Model();

$count = $Model->query("SELECT count(*) as sum FROM (select id FROM `view_patient` where $where GROUP by id) aa");

$patient_list['count'] = $count[0]['sum'];

$patient_list['result'] = $ViewPatientLogic->findInfobyCondition($where,$num,$p,'id desc','id','id,cname,patientid,hospitalid,hospitalname,sex,age');

     //哪一個有條件查詢 這個帶條件的查詢就標記顏色

foreach ($patient_list['result'] as $key => $value) {

if (strpos($value['patientid'], $search_pid) !== false) {

$patient_list['result'][$key]['patientid'] = str_replace($search_pid, '<f . $search_pid . '</font>', $value['patientid']);

}

if (strpos($value['cname'], $search_cname) !== false) {

$patient_list['result'][$key]['cname'] = str_replace($search_cname, '<f . $search_cname . '</font>', $value['cname']);

}

if(strpos($value['hospitalid'],$hospitalid) !== false){

$patient_list['result'][$key]['hospitalid'] = str_replace($hospitalid,'<f>

}

}

echo json_encode($patient_list);

exit;

}

本文內容整理自網絡, 文中所有觀點看法不代表淘大白的立場