本文介绍了用php显示MySQL数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码显示我的表 CarCollection 中的所有记录.现在我只能返回第一条记录.我怎样才能做到这一点?

I am trying to display all records from my table CarCollection using the following code. Right now I am only able to return the 1st record. how can I achieve this?

$connection = mysql_connect("localhost","USER_NAME","PASSWORD");
if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE_NAME", $connection);

$result = mysql_query("SELECT * FROM CarCollection");
$row = mysql_fetch_array($result);

mysql_close($connection);

推荐答案

<?php

$connection = mysql_connect("localhost","USER_NAME","PASSWORD");
if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE_NAME", $connection);

$result = mysql_query("SELECT * FROM CarCollection");
while($row = mysql_fetch_array($result)){

echo $row[0];
echo $row[1];
}


mysql_close($connection);
?>

这篇关于用php显示MySQL数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:42