2011-08-08 73 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 />'; 
}