我想根据卷号创建一个学生座位安排表 以这种格式(垂直)
Row 1 Row 2 Row 3 Row 4
a e i m
b f j n
c g k o
d h l p
根据变量rows
colums
和$rows and $cols
的数量可能会有所不同
$sql= "SELECT rollno FROM student WHERE batch= '".mysqli_real_escape_string($con, $_POST['batch'])."'";
$result = mysqli_query($con, $sql);
if(!$result)
{
echo 'Something went wrong. Please try again';
}
else
{
while($resulrow = mysqli_fetch_assoc($result))
{
$array[]=$resultrow['rollno'];
}
现在我有$array[]
,其中包含学生名单的列表。
我想在roll numbers
和vertical display
(顶部)的表格中显示这些every row should display row number in the table head
。
答案 0 :(得分:0)
这是一种可行的方法:
$sql = "SELECT col_a, col_b, ... FROM student WHERE batch=?";
$stmt = mysqli_prepare($con, $sql);
mysqli_stmt_bind_param($stmt, 's', $_POST['batch']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$a = array();
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {
$a['col_a'][$i] = $row['col_a'];
$a['col_b'][$i] = $row['col_b'];
// .... other columns
++$i;
}
$rows = count($a['col_a']);
显示表格:
<table><thead><tr>
<?php for ($j = 1; $j <= $rows; ++$j) {
?><th>Row <?php echo $j; ?></th><?php
} ?>
</tr></thead><tbody>
<?php foreach ($a as $col) {
?><tr><?php
foreach ($col as $row) {
?><td><?php echo $row; ?></td><?php
}
?></tr><?php
} ?>
</tbody></table>