dongyupen6269 2018-06-04 15:14
浏览 73
已采纳

想尝试一些标记<option> </ option>的循环

Here, i'am had some case that i thought that are uniq for me. this the problem, i want to looping some tag 3 times. The loop is work, but when it was input to database... just 1 loop that worked.

Here the Screenshot,

The value of loop

Result of loop

<td>
    <label for="baris">Baris</label>
    <select name="baris">
        <option value="">--</option>
        <?php 
            for ($i2=A; $i2 < F; $i2++) { 
                echo "<option name='".$i2."'>".$i2."</option>";
            }
         ?>
    </select>
</td>
<td>
    <label for="kolom">Kolom</label>
    <select name="kolom">
        <?php 
            for ($i3=1; $i3 <= 10; $i3++) { 
                echo '<option name="'.$i3.'">'.$i3.'</option>';
            }
         ?>
    </select>
</td>

also this code for input to database

<?php     
                if(isset($_POST['masukan'])){
                    $nama = htmlspecialchars($_POST['nama']);
                    $email = htmlspecialchars($_POST['email']);
                    $jk = htmlspecialchars($_POST['jk']);
                    $notlp = htmlspecialchars($_POST['notlp']);

                    $queryinput = mysqli_query($link, "UPDATE tb_customer 
                                                        SET nama='$nama',
                                                            email='$email',
                                                            notlp='$notlp',
                                                            jk='$jk'

                                                        WHERE id_cust='$id_cust1'    
                                                        ");

                    $querytampil = mysqli_query($link, "SELECT * FROM tb_customer WHERE id_cust ORDER by id_cust desc limit 1");
                    $dcus = mysqli_fetch_assoc($querytampil);
                    $id_cust = $dcus['id_cust'];

                    $querytampil2 = mysqli_query($link, "SELECT max(num_ticket)AS num  FROM tb_ticket");
                    $dnumti = mysqli_fetch_assoc($querytampil2);
                    $num_ticket = $dnumti['num'];
                    $hasil = $num_ticket + 1;

                    for ($i5= 1; $i5 <= $p; $i5++) { 

                    $baris = htmlspecialchars($_POST['baris']);
                    $kolom = htmlspecialchars($_POST['kolom']);
                        if($queryinput){
                            $id_flight = $data['id_flight'];
                            $queryinput2 = mysqli_query($link, "INSERT INTO tb_ticket VALUES('','$id_cust','$id_flight','$hasil','','','','','$id_dest','$id_ori', '$baris', '$kolom')");

                            if ($queryinput2) {
                                $querytampil3 = mysqli_query($link, "SELECT * FROM tb_ticket order by num_ticket desc limit 1");
                                $dtick = mysqli_fetch_assoc($querytampil3);
                                $nt = $dtick['num_ticket'];
                                echo "<script>alert('Succes.')</script>";
                                echo '<script>window.location="pembayaran.php?num_ticket='.$nt.'&&id_cust='.$id_cust.'"</script>';
                            }else{
                            echo "<script>alert('Your data cannot send.')</script>";
                            }
                        }else{
                            echo "<script>alert('Your data cannot send, please check your input data.')</script>";
                        }
                    }
                }
            ?>

Bad engslish sorry*

  • 写回答

1条回答 默认 最新

  • dpw30157 2018-06-04 15:45
    关注

    If I got this correct; it's because you are not setting your html variables as an array.

    The first changes you need to make are within your view page..

    <select name="baris"> -> <select name="baris[]">

    <select name="kolom"> -> <select name="kolom[]">

    This sets your $_POST['baris'] and $_POST['kolom'] as arrays.

    Since you're already looping...

    for ($i5= 1; $i5 <= $p; $i5++) { 
        $baris = htmlspecialchars($_POST['baris']);
        $kolom = htmlspecialchars($_POST['kolom']);    
    

    This stuff now needs to access the relevant array... And becomes...

    for ($i5= 1; $i5 <= $p; $i5++) { 
        $baris = htmlspecialchars($_POST['baris'][$i5]);
        $kolom = htmlspecialchars($_POST['kolom'][$i5]);      
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀