我有一个php数组,它包含来自我的数据库$name[] = $row['name']的信息。还有大约3行容器email、age和screen-resolution。
我正试着把它整齐地塞进一张桌子上,看上去像:
name----------email----------age----------screen-res
name1---------email1--------age1---------res1
name2---------email2--------age2---------res2
然而,我目前的情况如下:
name----------email----------age----------screen-res
name1---------name2----------name3------name4---------name5------name6-------name7------name8
email1---------email2----------email3------email---------email5------email6-------email7
我的密码
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Screen-Res</th>
</tr>
<?php
echo "<tr>";
foreach ($name as $nameVal) {
echo "<td>$nameVal</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($email as $emailVal) {
echo "<td>$emailVal</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($age as $ageVal) {
echo "<td>$ageVal</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($screen-res as $screen-resVal) {
echo "<td>$screen-resVal</td>";
}
echo "</tr>";
?>
</table>
发布于 2015-08-11 17:18:24
您的表格式不正确。你的桌子看起来像这样。好的是,对于所有的数据,只需要一个数组。
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Screen-Res</th>
</tr>
<?php
foreach ($rows as $row) {
echo "<tr>";
echo "<td>".$row['nameVal']."</td>";
echo "<td>".$row['emailVal']."</td>";
echo "<td>".$row['ageVal']."</td>";
echo "<td>".$row['screen-resVal']."</td>";
echo "</tr>";
}
?>
</table>https://stackoverflow.com/questions/31947981
复制相似问题