gpt4 book ai didi

php - 使用 PHP 将 html 输出中的座位组织成表格行

转载 作者:行者123 更新时间:2023-11-29 11:06:00 25 4
gpt4 key购买 nike

我正在整理一些东西,让用户可以预订电影放映的座位。每次放映的行号和座位号都存储在数据库中。我目前正在通过以下方法提取它们,以便用户可以单击座位按钮来选择预订的座位:

echo "<form>";
echo "<table>";
while($row = mysqli_fetch_assoc($result)){
$rownum = $row['row'];
$seat = $row['seat'];

echo "<tr><td><button type=\"submit\" name=\"seatsel\" value=\"$rownum$seat\">$rownum$seat</button></td></tr>";
}
echo "</table>";

现在,这仅输出 html,将所有按钮显示为表中的一行。我希望输出能够显示电影屏幕中每个 table 行的单个 table 行的座位。鉴于每行的长度不同,我不确定如何准确执行此操作。例如,A 排有 12 个座位,而 C 排有 8 个座位。

实现这一目标的最佳方法是什么?

最佳答案

您可以轻松更新代码,以便每次 mysql 行有另一个值时您都会获得一个新的表行。需要注意的一件事是,您可能需要添加(取决于您是否已经对结果进行排序)以下 ORDER BY row,seat

echo "<form>";
echo "<table>";
echo "<tr>";
while($row = mysqli_fetch_assoc($result)){
if (!isset($oldrownumber)) $oldrownumber = $row['row'];
else if ($oldrownumber != $row['row']) {
echo "</tr><tr>";
$oldrownumber = $row['row'];
}
$rownum = $row['row'];
$seat = $row['seat'];

echo "<td><button type=\"submit\" name=\"seatsel\" value=\"$rownum$seat\">$rownum$seat</button></td>";
}
echo "</tr>";
echo "</table>";

关于php - 使用 PHP 将 html 输出中的座位组织成表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41399086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com