doufanglian7585 2016-12-30 16:00
浏览 25
已采纳

使用PHP将html输出中的席位组织成表行

I'm putting together something that's mean to allow for a user to book seats for a cinema showing. The row and seat numbers for every showing are stored in the database. I'm currently extracting them in the following method so that users can click on a seat button to select that seat for their booking:

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>";

Right now this just outputs html showing all of the buttons as a single row in the table. I'd like the output to show seating across a single table row for every one of the table rows in the cinema screen. I'm not sure how to do this exactly given that each row is of differing lengths. E.g row A has twelve seats while row C has eight.

What would be the best way of accomplishing this?

  • 写回答

1条回答 默认 最新

  • duangua6912 2016-12-30 17:36
    关注

    You could easily update your code so that you will get a new table row every time the mysql row has another value. One thing to note is that you might want to add (depending on whether you're already sorting your results) the following 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>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。