2014-02-20 62 views
0

我已經從php-MySQL中的幾個sql短語中得到了結果。 我的$ sql1和結果查詢短語如下所示。我應該如何在php中使用array_intersect函數而不是MySQL交集?

$sql1= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
FROM code_co 
LEFT JOIN code_en ON code_en.code = code_co.code 
LEFT JOIN note ON note.code = code_co.code 
... 
where condition 
$result1= mysqli_query($con,$sql1); 

但我有9個SQL查詢短語,就像上面的代碼。在9 sql查詢中選定的列是相同的。那就是

$sql2= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
FROM code_co 
LEFT JOIN code_en ON code_en.code = code_co.code 
LEFT JOIN note ON note.code = code_co.code 
... 
where condition 
$result2= mysqli_query($con,$sql2); 
... 
$sql9= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
FROM code_co 
LEFT JOIN code_en ON code_en.code = code_co.code 
LEFT JOIN note ON note.code = code_co.code 
... 
where condition 
$result9= mysqli_query($con,$sql9); 

最後我想得到9個結果的交集,但不支持MySQL。 所以我想通過php代碼來解決這個問題。 這是array_intersect()函數。 但我不知道如何使用它。

while($row1= mysqli_fetch_array($result1)) 

while($row2= mysqli_fetch_array($result2)) 
    .... 
while($row9= mysqli_fetch_array($result9)) 

$intersect = array_intersect($row1, $row2, $row3, $row4, ...., $row9); 
print_r($intersect); 
mysqli_close($con); 
?> 

沒有錯誤信息,但沒有顯示任何內容。 我首先在這段代碼中使用了array_intersect函數。 請給我一個建議。 謝謝你的關注。

回答

1

與PHP一起使用會導致死亡,並且消耗資源非常大。如果您只是在要交叉的鍵字段中使用as條件在所有大查詢之間進行INNER JOIN,則您將直接找到要查找的交點。

其他的事情,也許什麼都不顯示,因爲你沒有向屏幕扔任何錯誤,檢查你的系統和應用程序中的PHP錯誤配置,以使它們在開發的地方。

+0

謝謝你的忠告! – Drohjho

相關問題