I know this question might be very basic for someone experienced. But I'm still in the learning process so I need some help.
I want to populate a session array with data that's coming from the database. There can be multiple items in the session array. I'm trying to do it like this -
$sql = mysqli_query($con, "SELECT * FROM `purchase_info_details` WHERE `purchase_details_id` = '$pur_det_id'");
while ($row = mysqli_fetch_array($sql)) {
$data[$i]['purchase_details_id'] = $row['purchase_details_id'];
$data[$i]['cid'] = $row['id'];
$data[$i]['item_id'] = $row['item_id'];
$data[$i]['unit_id'] = $row['unit_id'];
$data[$i]['quantity'] = $row['quantity'];
$data[$i]['price'] = $row['price'];
$data[$i]['conv_rate'] = $row['conv_rate'];
$_SESSION['list1_data']['purchase_details_id'] = $data[$i];
}
FYI: purchase_details_id is the primary key. This code works partially. What I mean is I only get one row from the table in my session array but I need to get all the rows from the table that matches my SQL query.
I've been searching for a relevant example on the internet but yet to find any. I'm really stuck with it and couldn't find any solution. Please help!
Thanks!!
$_SESSION['list1_data'][] = $data[$i];