2014-09-25 47 views
0
$to=$_POST['to']; 
$from=$_POST['from']; 
$repeat=$_POST['repeat']; 


    $mysqlquery= mysql_query("select count(patient_id) as idpateint,patient_id from patient where STR_TO_DATE(date_enter,'%d/%m/%Y') between STR_TO_DATE('$repeat','%d/%m/%Y') and STR_TO_DATE('$to','%d/%m/%Y') and patient_type='opd' and patient_id = (select patient_opd from patient where STR_TO_DATE(date_enter,'%d/%m/%Y') between STR_TO_DATE('$from','%d/%m/%Y') and STR_TO_DATE('$to','%d/%m/%Y') and patient_type='opd')")or die('invalid'.mysql_error()); 
     while($mysqlquery1=mysql_fetch_array($mysqlquery)){ 
    echo $mysqlquery1['idpateint']; 
    } 

這是sql查詢。我正在得到如何解決這個問題。請有人幫助解決問題。謝謝如何解決invalidSubquery返回多於1行

回答

0

改爲改爲IN

... and patient_id IN (select patient_opd ... 
        ^^---- 

=型平等測試純粹是用於單值單值的比較,例如

42 = 42 

你的子查詢返回的多個記錄,這意味着DB試圖做

42 = 42,107,etc.... 
+0

還有沒有其他的解決辦法? bcz我得到輸出爲0. – user12345 2014-09-25 17:09:31

+0

也許它是'$ myslquery1 ['idpatient']'?不知道。試試'var_dump($ mysqlquery1)'來看看你真正得到了什麼。 – 2014-09-25 17:11:20

+0

$ mysqlquery = mysql_query(「select count(patient_id)as idpateint,patient_id from STR_TO_DATE(date_enter,'%d /%m /%Y')between STR_TO_DATE('$ repeat','%d /%m /% (從患者中選擇patient_type ='opd'和STR_TO_DATE(date_enter,'%d')和patient_type ='opd'和patient_id in (''從','%d /%m /%Y')和STR_TO_DATE('$到','%d /%m /%Y'))「之間的/%m /%Y'死('invalid'.mysql_error()); ($ mysqlquery1 = mysql_fetch_array($ mysqlquery)){ echo $ mysqlquery1 ['idpateint']; }注意:未定義變量:重複 – user12345 2014-09-26 09:39:48

相關問題