我正在建立一个网站,它将从 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);
?>