繁体   English   中英

PHP中的While循环形式

[英]While loop form in PHP

我想用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>

您无需根据循环为输入名称指定一个计数器。 您可以使用数组符号作为输入名称,例如:

<?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中的数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM