我正在尝试使用从数据库中获取的数据打印出一个表格。这是代码
<?php
$host = "localhost";
$user = "root";
$pass = "";
$databaseName = "caliban";
$tableName = "caliban";
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$result = mysql_query("SELECT * FROM $tableName"); //query
$array = mysql_fetch_assoc($result); //fetch result
//--------------------------------------------------------------------------
// 3) echo result as json
//--------------------------------------------------------------------------
$result = mysql_query("SELECT * FROM $tableName"); //query
$rows = Array();
$i=0;
while($row = mysql_fetch_assoc($result)){
//array_push($rows, $row);
$rows[$i++] = $row;
}
for($j=0;$j<count($rows); $j++){
echo
"<table><tbody><tr id='$rows[$j]['id']'>
<td><input type='checkbox' /></td>
<td>$rows[$j]['firstname']</td>
<td>$rows[$j]['lastname']</td>
<td>$rows[$j]['city']</td>
<td>$rows[$j]['continent']</td>
</tr></tbody></table>";
}
?>
错误重复 8 次,因为这些是我拥有的总行数。