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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器