2011-08-08 74 views
1

我有一個php網頁,我希望它一次顯示所有論壇主題。他是我擁有的當前數據庫代碼,它只顯示在線程上。從mysql顯示多條記錄

mysql_connect("localhost", "", "") or die("could not connect to mysql"); 
mysql_select_db("") or die("could not connect to db"); 


$result = mysql_query("SELECT * FROM reference") 
or die(mysql_error()); 


$row = mysql_fetch_array($result); 

echo "<strong>ref_thread_id:</strong> ".$row['ref_thread_id'].'<br />'; 
echo "<strong>ref_thread_prefix:</strong> ".$row['ref_thread_prefix'].'<br />'; 
echo "<strong>ref_thread_topic:</strong> ".$row['ref_thread_topic'].'<br />'; 
echo "<strong>ref_thread_content:</strong> ".$row['ref_thread_content'].'<br />'; 

我該如何獲得它吐出此表中的每條記錄?

謝謝。

回答

2

你需要使用while循環。提取函數一次只能得到一行。

while($row = mysql_fetch_array($result)) { 
    echo ... 
} 
1

你只是抓住了第一個記錄,遍歷每個:

while ($row = mysql_fetch_array($result)) { 
    echo "<strong>ref_thread_id:</strong> ".$row['ref_thread_id'].'<br />'; 
    echo "<strong>ref_thread_prefix:</strong> ".$row['ref_thread_prefix'].'<br />'; 
    echo "<strong>ref_thread_topic:</strong> ".$row['ref_thread_topic'].'<br />'; 
    echo "<strong>ref_thread_content:</strong> ".$row['ref_thread_content'].'<br />'; 
}