Mutiple input array dengan value berbeda tiap row nya

saya ingin membuat multi insert. saat melooping modality(dengan metode SELECT dari table berbeda dengan variable "pk_mod") berhasil masuk ke database. namun ketika ingin input harga & qty. harga & qty nya tidak ikut ter looping(terforeach) meskipun coding nya suda saya letakan didalam foreach dan didalam database nya terinput "array" tidak sesuai dengan value yg saya input

penawaran.php
  <a href="generate.php"><button class="btn-success btn-penawaran">Tambahkan Data</button></a><br>
                        <form class="pnwrn" action="" method="POST">
                            <input type="hidden" name="total" value="<?php $_POST['count_add']; ?>">

                            <div class="form-group">

                                <label for="exampleFormControlSelect1">Rumah Sakit</label>
                                <select class="form-control" id="exampleFormControlSelect1" name="pk_kunjungan">
                                    <option>---Pilih Rumah Sakit---</option>
                                    <?php
                                        $result = mysqli_query($conn, "SELECT * FROM sales_kunjungan WHERE username = '$username'");
                                        while ($row = mysqli_fetch_assoc($result)) { ?>
                                        <option value=" <?php echo $row['pk_kunjungan'] ?>">
                                            <?php echo $row['rs_kunjungan'] ?>
                                        </option>
                                    <?php } ?>
                                </select>
                                <div class=" form-group">
                                    <label for="exampleFormControlSelect1">Sumber Dana</label>
                                    <select class="form-control" id="exampleFormControlSelect1" name="budget_funnel">
                                        <option>---Pilih Sumber Dana---</option>
                                        <option value="APBN">APBN</option>
                                        <option value="APBD">APBD</option>
                                        <option value="APBN-P">APBN-P</option>
                                        <option value="DAK">DAK</option>
                                        <option value="BLUD">BLUD</option>
                                        <option value="Swasta">Swasta</option>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label for="referensi">Referensi</label><br>

                                    <label class="radio-admin">
                                        <input type="radio" id="referensi" name="referensi" value="E-Catalogue"> E-Catalogue
                                        <span class="checkmark"></span>
                                    </label><br>

                                    <label class="radio-admin">
                                        <input type="radio" id="referensi" name="referensi" value="Non E-Catalogue" required>
                                        Non E-Catalogue
                                        <span class="checkmark"></span>
                                    </label><br>

                                </div>
                                <hr>
                            </div>

                            <?php for ($i = 1; $i <= $_POST['count_add']; $i++) { ?>
                                <!-- --------------------------------1----------------- -->
                                <div class="penwaran1">
                                    <h2><strong><?= $i; ?></strong></h2>
                                    <div class="form-group">
                                        <label for="exampleFormControlSelect1"><?php echo "Modality#$i"; ?></label>
                                        <select class="form-control" id="exampleFormControlSelect1" name="pk_mod1[]">
                                            <option>---Pilih Modality---</option>
                                            <?php
                                                    $result = mysqli_query($conn, "SELECT * FROM sales_modality");
                                                    while ($row = mysqli_fetch_assoc($result)) { ?>
                                                <option value=" <?php echo $row['pk_mod'] ?>">
                                                    <?php echo $row['nama_mod'] . ' Harga : ' . rupiah($row['harga_mod']) ?>
                                                </option>
                                            <?php } ?>
                                        </select>
                                    </div>

                                    <div class="form-group">
                                        <label for="harga_penawaran"><?php echo "Harga Penawaran 1" ?></label>
                                        <input type="text" class="form-control" id="harga_penawaran" name="harga_penawaran1[]" placeholder="Maksimal Disc 50%" pattern="[0-9]+" required>
                                    </div>

                                    <div class="form-group">
                                        <label for="qty"><?php echo "Qty Penawaran 1" ?></label>
                                        <input type="text" class="form-control" id="qty" name="qty1[]" placeholder="Qty penawaran.." pattern="[0-9]+" required>
                                    </div>
                                    <br>
                                    <hr>

                                    <br><br>
                                </div>
                            <?php } ?>

function penawaran nya :

function penawaran($pnwrn)
{
	global $conn;

	$q = mysqli_query($conn, 'SELECT MAX(pk_penawaran) as user_id from sales_penawaran');
	$row = mysqli_fetch_assoc($q);
	$ai = $row['user_id'] + 1;

	$qz = mysqli_query($conn, 'SELECT MAX(pk) as user_id from sales_funnel');
	$rowz = mysqli_fetch_assoc($qz);
	$aiz = $rowz['user_id'] + 1;

	$x = mysqli_query($conn, 'SELECT MAX(no_penawaran) as no_pen from sales_penawaran');
	$rowx = mysqli_fetch_assoc($x);
	$aix = $rowx['no_pen'];

	// $harga_penawaran = $pnwrn['harga_penawaran'];
	// $qty = $pnwrn['qty'];
	$budget = $pnwrn['budget_funnel'];

	$array_bln = array(1 => "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII");
	$bln = $array_bln[Date('n')];

	$thn = Date('Y');

	$pk_kunjungan = $pnwrn['pk_kunjungan'];
	$kunjungan = mysqli_query($conn, "SELECT * FROM sales_kunjungan WHERE pk_kunjungan = '$pk_kunjungan' ");
	$row_kunj = mysqli_fetch_assoc($kunjungan);
	$nama_kunjungan_penawaran = $row_kunj['nama_kunjungan'];
	$rs_kunjungan = $row_kunj['rs_kunjungan'];
	$alamat_kunjungan = $row_kunj['alamat_kunjungan'];
	$kota_kunjungan = $row_kunj['kota_kunjungan'];

	// 	foreach ($pk_mod as $pk_mod1) {
	// $pk_mod1 = implode("','", $pk_mod1)
	$tdate = date("m");
	if ($tdate == 01 or $tdate == 02 or $tdate == 03) {
		$dt = 'I';
	} elseif ($tdate == 04 or $tdate == 05 or $tdate == 06) {
		$dt = 'II';
	} elseif ($tdate == 07 or $tdate == 08 or $tdate == 09) {
		$dt = 'III';
	} else {
		$dt = 'IV';
	}

	// $count = $pnwrn['count'];

	$total = $pnwrn['total'];

	$nourut = substr($aix, 2, 4);
	$nourut++;
	$username = $pnwrn['username'];
	$nopen = sprintf("%04s", $nourut);
	$referensi = $pnwrn['referensi'];
	$no_penawaran = 'Q-' . $nopen . '/IPI/' . '/' . $username . '/' . $bln . '/' . $thn;

	$pk_mod = $pnwrn['pk_mod1'];

	foreach ($pk_mod as $pk_mod1) {

		$o = mysqli_query($conn, 'SELECT MAX(pk_order) as user_id from sales_order');
		$rowq = mysqli_fetch_assoc($o);
		$aoi = $rowq['user_id'] + 1;

		$qo = mysqli_query($conn, 'SELECT MAX(pk_penawaran) as user_id1 from sales_penawaran');
		$roworder = mysqli_fetch_assoc($qo);
		$ao = $roworder['user_id1'];

		$mod = mysqli_query($conn, "SELECT * FROM sales_modality WHERE pk_mod IN ('" . $pk_mod1 . "') ");
		$row_mod = mysqli_fetch_assoc($mod);
		$nama_mod = $row_mod['nama_mod'];
		$merk_mod = $row_mod['merk_mod'];
		$model_mod = $row_mod['model_mod'];
		$spek_mod = $row_mod['spek_mod'];
		$harga_mod = $row_mod['harga_mod'];

		$harga_penawaran = $pnwrn['harga_penawaran1'];
		$qty = $pnwrn['qty1'];

		$query2 = "INSERT INTO sales_order(pk_order, fk_penawaran, pk_mod_order, nama_mod_order, model_mod_order, merk_mod_order, spek_mod_order, harga_order, qty_order) VALUES ('$aoi', '$ao', '$pk_mod1', '$nama_mod', '$model_mod', '$merk_mod', '$spek_mod', '$harga_penawaran', '$qty')";
		mysqli_query($conn, $query2);
	}

daftar gambar<a href='https://imgur.com/a/fq1u2aU'>ss database</a>

avatar eggysetiawan
@eggysetiawan

2 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban