public function getProducts() { $db_handle = new DBController(); $conn = $db_handle->connectDB(); $results = $db_handle->runQuery($conn, "SELECT * FROM tblproduct ORDER BY id ASC"); return $results; }
<?php session_start(); $current_page_uri = $_SERVER['REQUEST_URI']; $part_url = explode("/", $current_page_uri); require_once "controller/dbcontroller.php"; $db_handle = new DBController(); $conn = $db_handle->connectDB(); if (!empty($_POST["action"])) { switch ($_POST["action"]) { case "add": if (!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery($conn, "SELECT * FROM tblproduct WHERE code='" . $_POST["code"] . "'"); $itemArray = array($productByCode[0]["code"] => array('name' => $productByCode[0]["name"], 'code' => $productByCode[0]["code"], 'quantity' => $_POST["quantity"], 'price' => $productByCode[0]["price"])); if (!empty($_SESSION["cart_item"])) { if (in_array($productByCode[0]["code"], $_SESSION["cart_item"])) { foreach ($_SESSION["cart_item"] as $k => $v) { if ($productByCode[0]["code"] == $k) { $_SESSION["cart_item"][$k]["quantity"] = $_POST["quantity"]; } } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"], $itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } break; case "remove": if (!empty($_SESSION["cart_item"])) {