$sth1 = $db->prepare($sstmt1); $sth1->execute(); $arr1 = $sth1->fetchAll(); $sstmt2 = "SELECT `barcode`, `product` FROM `items_alcohol` WHERE 1"; $sth2 = $db->prepare($sstmt2); $sth2->execute(); $arr2 = $sth2->fetchAll(); $products = array_merge($arr1, $arr2); //generate the site home. $site = new site("cart"); //call the genOpeneing method to generate the opening content of the home page. $site->genOpening(); //call the genSearch method to genreate the search bar on the top of the page. $site->genSearch(); //call readText method to pull information into the page from seperate source. $site->readText("cart"); // If we find sections of the cart set, display the table. // We are using map here because sizeof() doesn't handle nested arrays if (isset($_SESSION["cart"]) && @max(array_map('count', $_SESSION["cart"])) > 0) { // Generate the heading of the table echo "<table><tr><th>Product</th><th>Quantity</th></tr>"; //Iterate through the cart, setting the product name as $key and the quantity as $value foreach ($_SESSION["cart"] as $key => $value) { $productName = "Unknown Product"; // Echo a table row with the information and a button. foreach ($products as $row) { if ($row[0] == $key) { $productName = $row[1]; } } echo "<tr><td>{$productName}</td><td>{$value} <button onclick='action(\"remove\",\"{$key}\")'>- Remove</button></td></tr>";
$stmt2 = "SELECT `order_id`, `fName`, `lName`, `addr`, `ord` FROM `orders` WHERE order_id = :ord ORDER BY `order_id` DESC LIMIT 1"; $sth2 = $db->prepare($stmt2); $sth2->bindParam(":ord", $order); $sth2->execute(); $values = $sth2->fetchAll()[0]; echo "Order for {$values['lName']}, {$values['fName']}<br />"; echo "Shipped to {$values['addr']}<br />"; $contents = json_decode($values["ord"], true); echo "<table><tr><th>Product</th><th>Quantity</th></tr>"; foreach ($contents as $key => $value) { $productName = "Unknown Product"; // Echo a table row with the information and a button. foreach ($products as $row) { if ($row[0] == $key) { $productName = $row[1]; } } echo "<tr><td>{$productName}</td><td>{$value}</td></tr>"; } echo "</table>"; } catch (PDOException $e) { echo $e->gettext(); } } else { echo "Unknown order ID!"; } } //call readText method to pull information into the page from separate source. $site->readText("order"); //call genClosing method to generate bottom of page and close html. $site->genClosing();
// Create a new statement handle, with the statement we created above $sth = $db->prepare($stmt); // Replace the :type param with the type given @$sth->bindParam(":type", $type); // Execute the search against the database $sth->execute() or die("Unable to execute"); // Fetch the results from the statement handle $result = $sth->fetchAll(); // Create a new "site" object $site = new site(strtolower($type)); //call the genOpeneing method to generate the opening content of the page. $site->genOpening(); //call the genSearch method to generate the search bar on the top of the page. $site->genSearch(); // Display the text from our static contents $site->readText($type); // Echo the top of the table echo <<<ENDL <table class="sortable"> \t<tr> \t\t<th>Product</th> \t\t<th>Type</th> \t\t<th>Wholesale</th> \t\t<th>Quantity</th> \t\t<th class="nj sorttable_nosort">Add to Cart</th> \t</tr> ENDL; /* foreach($result as $row) { echo "<tr><td>{$row["Product"]}<br />(Barcode: {$row["Barcode"]})</td><td>{$row["Category"]}</td><td>\${$row["Price"]}.00</td><td>{$row["Stock"]}</td><td>"; if ($row["Stock"] < 1) { echo "This product is currently unavailable"; }
<?php //start the user session session_start(); //require the includes.php which ensures certain files are pulled in for database and site properties. require "includes.php"; //create a PDO connection to the mySQL databse. $db = new PDO("mysql:host={$GLOBALS['mysql_host']};dbname={$GLOBALS['mysql_database']}", $GLOBALS["mysql_user"], $GLOBALS["mysql_password"]) or die("Unable to connect to database."); //generate the site home. $site = new site("home"); //call the genOpeneing method to generate the opening content of the home page. $site->genOpening(); //call the genSearch method to genreate the search bar on the top of the page. $site->genSearch(); //call readText method to pull information into the page from separate source. $site->readText("welcome"); //call genClosing method to generate bottom of page and close html. $site->genClosing();