如何使用嵌套的foreach或for

时间:2016-08-25 07:20:41

标签: php html arrays for-loop foreach

我有一个HTML,我想将此表单插入表格。这个视图html:

enter image description here

上面的表格是动态的,我想将这些数据插入MySQL,我已经尝试过这个:



$id_po = $_POST['id_po'];
        $id_model = $_POST['id_model'];
        $id_user = $_SESSION['id_user'];
        $id_model_jml = count($id_model);
        for ($i = 0; $i < $id_model_jml; $i++) {
            $ukuran = $_POST['ukuran'][$i];
            $jumlah_hanca = $_POST['jumlah_hanca'];
            $jumlah_hanca_jml = count($jumlah_hanca);
            for ($x = 0; $x < $jumlah_hanca_jml; $x++) {
                $qry = $db->query("INSERT INTO hanca SET id_hanca=NULL, 
                       id_po='$id_po', id_model='$id_model[$i]', ukuran='$ukuran[$x]',
                       jumlah_hanca='$jumlah_hanca[$x]', id_user='$id_user' ");
                if ($qry) {
                    echo "berhasil simpan hanca";
                } else {
                    echo "gagal simpan hanca";
                }
            }
        }
&#13;
&#13;
&#13;

我想用什么方法?

0 个答案:

没有答案