我有以下php代码:
<?php
$connect = mysql_connect("localhost","root","") or die("Couldn't connect!");
mysql_select_db("cdcol") or die("There are no databases by that name");
$query = "select * from cds";
$result = mysql_query($query);
$record = mysql_fetch_array($result);
print_r($record);
?>
由于某种原因(你会告诉我为什么......)这段代码的输出是:
Array ( [0] => Beauty [titel] => Beauty [1] => Ryuichi Sakamoto [interpret] => Ryuichi Sakamoto [2] => 1990 [jahr] => 1990 [3] => 1 [id] => 1 )
即,不是获取所有表,而是获取它的第一行。有什么建议吗?
谢谢
答案 0 :(得分:0)
mysql_fetch_array()一次只返回一行。
PHP文档:mysql_fetch_array
你必须在mysql结果上创建一个循环并循环:
while ($row = mysql_fetch_array($query)) {
print_r($row);
}
答案 1 :(得分:-1)
把它放入循环
while ($record = mysql_fetch_array($result)) {
print_r($record);
}