如何使用动态更改的数组值循环行?
而不是:
while($row = mysqli_fetch_array($result))
{
echo "<tr><td align='left'>" . $row['english'] . "</td></tr>";
echo "<tr><td align='left'>" . $row['spanish'] . "</td></tr>";
echo "<tr><td align='left'>" . $row['italian'] . "</td></tr>";
.
.
.
}
我需要这样的东西:
while($row = mysqli_fetch_array($result) and $property = mysqli_fetch_field($result))
{
$name = $property->name; // array?
echo "<tr><td align='left'>" . $row[$name] . "</td></tr>";
}
答案 0 :(得分:1)
只需添加内循环:
while($row = mysqli_fetch_row($result)) {
foreach($row as $column => $value) {
// $column is column name 'englsih', 'spanish' etc.
echo "<tr><td align='left'>" . $value . "</td></tr>";
}
}