如何将sql数据放入html表

时间:2017-03-31 14:20:51

标签: php html mysql sql

我正在尝试将我的SQL数据放入HTML数据中,这是我到目前为止的代码,但它还没有工作。我试图将HTML放入我的PHP代码中我想知道我是否应该这样做(将PHP放入HTML),任何回复都非常感谢

  while ($rowObj = $queryResult->fetch_object()) {
echo "<tr>";
echo"<td>" . $AE_events ['eventTitle'] . "</td>;
echo"<td>" . $AE_events ['eventDescription'] . "</td>;
echo"<td;>" . $AE_events ['eventStartDate'] . "</td>;
echo"<td>" . $AE_events ['eventEndDate'] . "</td>;
echo"<td>" . $AE_events ['eventPrice'] . "</td>;

    $AE_eventTitle = $rowObj->eventTitle;
    $AE_eventDescription = $rowObj->eventDescription;
    $AE_eventStartDate = $rowObj->eventStartDate;
    $AE_eventEndDate = $rowObj->eventEndDate;
    $AE_eventPrice = $rowObj->eventPrice;
    echo "<div>  $AE_eventTitle<br> $AE_eventDescription<br>   
$AE_eventStartDate<br> 
$AE_eventEndDate<br> $AE_eventPrice<br> </div>";

}

1 个答案:

答案 0 :(得分:0)

如果要在PHP中使用数据绘制表格,则必须使用嵌套循环。第一个循环管理行,嵌套的循环管理列。示例:

$data = [
    [1, 3, 5],
    [2, 4, 6]
];
print "<table>";
for ($i = 0; $i < count($data); $i++) {
    $row = $data[$i];
    print "<tr>";
    for ($k = 0; $k < count($row); $k++) {
        print "<td>{$row[$k]}</td>";
    }
    print "</tr>";
}
print "</table>";

输出:

<table>
    <tr>
        <td>1</td>
        <td>3</td>
        <td>5</td>
    </tr>
    <tr>
        <td>2</td>
        <td>4</td>
        <td>6</td>
    </tr>
</table>