簡體   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