<?php
include '../db/db.php';
session_start();
$log= htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');

if (empty($log)) {

	$redirectUrl = "../index.php";
	echo "<script type=\"text/javascript\">";
	echo "window.location.href = '$redirectUrl'";
	echo "</script>";

}

	if (array_key_exists('cart_details_load', $_POST)) {//data table

		$u_id = htmlspecialchars(trim($_POST['u_id']), ENT_QUOTES, 'UTF-8');
		$inv_id = htmlspecialchars(trim($_POST['inv_id']), ENT_QUOTES, 'UTF-8');

		$sql = "SELECT
		cart_details.id,
		cart_details.user_id,
		cart_details.Item,
		cart_details.Qty,
		cart_details.price,
		cart_details.order_id,
		cart_details.inv_id,
		cart_details.`status`,
		cart_details.conform_status,
		cart_details.del_date,
		cart_details.order_date,
		cart_details.del_confirm,
		items.item_code
		FROM
		cart_details
		Inner Join items ON cart_details.Item_Code = items.id
		WHERE cart_details.user_id = '$u_id' AND cart_details.inv_id = '$inv_id'";

		$data = array();
		$result = mysqli_query($conn,$sql);
		while ($row = mysqli_fetch_assoc($result)) {
			$data[] = $row;
		}
		echo json_encode($data);
	}
	?>