2013-06-11 69 views
-2

執行以下代碼後,如果啓用$q3刪除查詢,$i不會回顯。如果我評論它或刪除$q3,那麼一切都很好。PHP爲什麼這個代碼不會回顯?

我該如何得到這個工作?

$isfound = in_array("empty",$currentrooms0); 
if($isfound===true){ 
    for($i=0; $i<count($currentrooms0);$i++){ 
     if($currentrooms0[$i]=="empty"){ 
      $q3=mysqli_query($conn0,"delete from room_attributes where _current_created_rooms='empty' order by id desc limit 1")or die(mysqli_error($conn0));  
      echo $i-1; 
      break; 
     } 
    } 
+0

您的查詢失敗並輸出錯誤 在任何情況下? – Pudge601

+1

你有沒有啓用display_errors? – Spudley

+1

檢查代碼中的「{」和「}」。 –

回答

0

它不會迴應的原因是因爲在你的SQL和mysqli_query回報在這種情況下錯誤的錯誤。

的SQL導致一個錯誤,因爲你不能使用ORDER BY直接屬於DELETE

一個WHERE子句中如果你可能要考慮使用這個SQL和你的代碼你正在尋找刪除最上面的屬性,那麼什麼應該管用。

DELETE FROM room_attributes 
WHERE id IN (
    SELECT id FROM room_attributes 
    WHERE _current_created_rooms='empty' 
    ORDER BY id DESC 
    LIMIT 1 
) 
+0

這裏是答案[code] $ isfound = in_array(「empty」,$ currentrooms0);對於($ i = 0; $ i $ i-1){echo 0;} else {echo $ i-1;} break; } } [/ code] – calmchess

0

我覺得你有與mysqli_connect問題,請嘗試以下做..

if($q3 ===TRUE){ 
    echo $i-1; 
    break; 
}else{ 
    echo "Connection Problem"; 
} 
+0

$ isfound = in_array(「empty」,$ currentrooms0);對於($ i = 0; $ i calmchess

-1

的OP寫道:

這裏就是答案:

$isfound = in_array("empty",$currentrooms0); 
if($isfound===true){ 
    for($i=0; $i<count($currentrooms0);$i++){ 
     if($currentrooms0[$i]=="empty"){ 
      $q3=mysqli_query($conn0,"delete from room_attributes where _current_created_rooms='empty' order by id desc limit 1") or die(mysqli_error($conn0)); 
      if(i>$i-1) {echo 0;}else{echo $i-1;} 
      break; 
     } 
    } 
+0

([在評論中回答並轉換爲社區wiki](http://meta.stackoverflow.com/questions/251597/question-with-no-answers-but-issue-solved-in-the -註釋)。) –