2013-05-19 92 views
0

我有以下的PHP/MySQL代碼:記錄檢索兩次

$wp_sql_query_text = "SELECT table1.field1, table1.field2, table1.field3, 
table2.field1, table2.field2,table3.field1, table3.field2 from table1 

INNER JOIN table2 ON table1.field2=table2.field1 
INNER JOIN table3 ON table1.field3=table3.field1 
WHERE table1.field1 > SOME_VALUE 
ORDER BY table1field1"; 


echo $wp_sql_query_text;  
$get_app_history = mysqli_query($conn,$wp_sql_query_text); 
$app_entry = mysqli_fetch_assoc($get_app_history); 

//some additional code for initialization of counters and variables 

while ($app_entry = mysqli_fetch_assoc($get_app_history)){ 
    //some processing 
} 

簡而言之

1)有3個表 - 表1,表2和表3。

2)table1有3個字段 - field1,field2和field3。

3)表2表3和具有2個字段

每個

'echo'ing sql查詢後,我剪切並粘貼sql在我的phpmyadmin和記錄只檢索一次。

但是,在我的頁面上,我獲取了兩次相同的記錄。

回答

0

這是因爲你獲取你的結果兩次

$app_entry = mysqli_fetch_assoc($get_app_history); // first fetch 

.......some additional code for initialization of kounters and variables..... 

while ($app_entry = mysqli_fetch_assoc($get_app_history)) // second fetch with a loop 

我建議刪除第一,並保持您可能會在多個結果

情況下使用循環