if(mysql_num_rows($result) == 0)
{
exit;
}
else{
$data = array();
while($row = mysql_fetch_assoc($result))
{
$data[] = $row;
}
$columns = array_keys(reset($data));
echo '<table>';
echo '<table border="3">';
echo '<tr>';
foreach($columns as $column)
{
echo "<th>$column</th>";
}
echo '</tr>';
foreach($data as $row);
{
echo '<tr>';
foreach($columns as $column)
{
echo '<td>'.$row[$column].'</td>';
}
echo '</tr>';
}
echo '</table>';
}
我(显然)不是MySQL或PHP的专家,我不确定我做错了什么。它只显示 MySQL 表中的最后一行。我错过了什么吗?
我认为您需要像这样填充行数组:
$data = array();
$index = 0;
while($row = mysql_fetch_assoc($result))
{
$data[$index] = $row;
$index++;
}