我想在PHP中开发while循环形式。我能够在每一行中创建不同的名称,但不知道如何在下一页中处理POST值。
以下是我的代码:
<form action="sms.php" method="post" enctype="multipart/form-data">
<table class="table table-hover" style="border: groove;">
<thead>
<tr>
<th>Student Id</th>
<th>Student Name</th>
<th>Phone Number</th>
<th>Today's Attendance</th>
</tr>
</thead>
<tbody>
<?php
$c = 1;?>
<?php
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$stmt = $user->present();
while($ro1 = $stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><input name ="uname" id ="uname" style ="border:none;background: none;" value = "<?php echo $ro1['user_id'] ?>" readonly/></td>
<td><?php echo $ro1['first_name'] ?> <?php echo $ro1['last_name'] ?></td>
<td><input name = "list<?php echo $c++ ?>" id ="cont1" type="number" style ="border:none;background: none;" onBlur="checkAvailability1a()" value="<?php echo $ro1['parent_contact'] ?>"/></td>
<td><input id="press1" name="press1" type="button" value="<?php echo $ro1[$_SESSION['dyy']] ?>" onclick="return change(this);" onBlur="checkAvailability()" class="w3-button w3-teal"/></td>
</tr>
<?php } ?>
</tbody>
</table>
<button name="back"><a href = 'attendance.php'>< Back</a></button>
<button type="submit" name="next">Next</a></button>
答案 0 :(得分:0)
您不需要根据循环为输入名称提供计数器。您可以使用数组表示法作为输入名称,例如:
<?php
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$stmt = $user->present();
while($ro1 = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><input name ="uname[]" id ="uname" style ="border:none;background: none;" value = "<?php echo $ro1['user_id'] ?>" readonly/></td>
<td><?php echo $ro1['first_name'] ?> <?php echo $ro1['last_name'] ?></td>
<td><input name = "list[]" id ="cont1" type="number" style ="border:none;background: none;" onBlur="checkAvailability1a()" value="<?php echo $ro1['parent_contact'] ?>"/></td>
<td><input id="press1" name="press1[]" type="button" value="<?php echo $ro1[$_SESSION['dyy']] ?>" onclick="return change(this);" onBlur="checkAvailability()" class="w3-button w3-teal"/></td>
</tr>
<?php } ?>
然后在下一页( sms.php )中,您可以使用$_POST['list']
(不带[])获取请求参数。该参数将是php中的一个数组。