2012-10-14 73 views
-2

我不知道爲什麼,一環,應該是有限的,像mysql_fetch_array()這樣無限循環

while ($noticia = mysql_fetch_array(mysql_query("SELECT * FROM noticias WHERE deletada='0' ORDER BY id ASC"))) 
{ 
    // echo $noticia['blabla']; 
} 

正在做無限循環,並在頁面沒有加載...

爲什麼會發生?

+0

因爲每次當你正在執行查詢,以便每次你會得到的數據 – GBD

+0

mysql_ *已被棄用所以使用'pdo'或'mysqli' – StaticVariable

回答

1

嘗試。

$query = mysql_query("SELECT * FROM noticias WHERE deletada='0' ORDER BY id ASC"); 
while($noticia = mysql_fetch_array($query)){ 
    echo $noticia['table_field']; 
} 
+0

'mysql_ *'已被棄用,所以不要建議 – StaticVariable

4

它可以通過

$qry = mysql_query("SELECT * FROM noticias WHERE deletada='0' ORDER BY id ASC") 

    while ($noticia = mysql_fetch_array($qry)) 
    { 
     // echo $noticia['blabla']; 
    } 

來解決,但mysql_*函數已不再那麼請使用PDO或mysqli的

與PDO一個簡單的簡單here is very simple pdo tutorial

$pdo = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password'); 
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 

$query = $pdo->prepare("SELECT * FROM noticias WHERE deletada='0' ORDER BY id ASC"); 
$query->execute(); 
$row=$articlequery->fetch(pdo::FETCH_ASSOC); 
+1

現在它的工作,謝謝! –

+0

@SergioToledoPiza非常歡迎 –

+0

@SergioToledoPiza如果這個答案幫助你,你可以通過點擊投票區下面的'right'標記來接受這個答案 – StaticVariable