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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用