我想将数据保存到数组中并在输入数据后使用会话。我已经尝试过并且成功了。但我想显示从数据库中获取的一些数据并将其保存到数组和会话中。我尝试过添加数据库查询,但数据只能保存一项数据。
<?php
if (!isset($_SESSION)) {
session_start();
# code...
}
include_once "AlgoCBC.php";
function additem($jns, $hrg, $hrg_tw, $total, $kt_satu, $kt_dua, $kt_tiga, $kt_empat, $kt_lima, $kt_enam, $kt_tujuh){
if (empty($_SESSION['$jns'])) {
include "koneksi.php";
$_SESSION['jenis'] = array();
$jen = array_push($_SESSION['jenis'], $jns);
foreach ($jen as $id) {
$sql = mysqli_query($kns, "Select stok.id_stok as id_stok, merk.nama_merk as nama_merk, model.nama_model as nama_model, stok.warna as warna FROM stok INNER JOIN model On stok.id_model=model.id_model INNER JOIN merk ON model.id_merk=merk.id_merk where id_stok = '$id' ") or die(mysqli_error($kns));
while ($y=mysqli_fetch_array($sql)) {
$mrk[] = implode("", DekripCBC($y['nama_merk']));
$mdl[] = implode("", DekripCBC($y['nama_model']));
$wrn[] = implode("", DekripCBC($y['warna']));
}
}
$_SESSION['merk'] = array();
$_SESSION['model'] = array();
$_SESSION['warna'] = array();
$_SESSION['kuantiti'] = array();
$_SESSION['harga'] = array();
$_SESSION['harga_tawar'] = array();
$_SESSION['harga_jual'] = array();
}
$kn = $kt_satu + $kt_dua + $kt_tiga + $kt_empat + $kt_lima + $kt_enam + $kt_tujuh;
array_push($_SESSION['merk'], $mrk);
array_push($_SESSION['model'], $mdl);
array_push($_SESSION['warna'], $wrn);
array_push($_SESSION['kuantiti'], $kn);
array_push($_SESSION['harga'], $hrg);
array_push($_SESSION['harga_tawar'], $hrg_tw);
array_push($_SESSION['harga_jual'],$total);
}
所以它只能保存1个数据。如果输入新数据,则先前的数据将丢失。
Helenr
慕娘9325324