Im建立一个网站,它将返回mysql的结果并将它们显示在网页上。 我在将数据存储在mysql中或检索数据 并将其显示在网页上没有问题。 当数据返回到页面时,我想将它存储在一个表中并运行一个循环,以便每个记录都会有一个像列表号一样向下递增的数字。 任何帮助,将不胜感激。 我一直运行到我的代码错误:显示来自mysql的数据,在表中显示
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("forloops", $con);
$result = mysql_query("SELECT * FROM userinfo ORDER BY age DESC");
echo "<table border='1'>
<tr>
<th>Position</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";
$counter = 0;
$position= 0;
$row = mysql_fetch_array($result);
if($counter <=10){
echo "<tr>";
echo "<td>" . $position . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
$counter++;
}
echo "</table>";
mysql_close($con);
?>
你得到了什么错误? – dziwna 2013-02-08 13:46:49