<?php

// we are now in presentation layer
// we will include business layer to load business logic
include "./business/business.php";
// init User Model from Business Logic
$product = new Product();
$category = $_POST["category"];
$data = $product->readAll();
if (isset($category) && $category) {
    if ($category != "Show all categories") {
        //echo "You entered all categories \n <br>";
        $data = $product->readByCategory($category);
    }
    //call special category
}
// prepare HTML Table
function getHTMLTable($tabledata)
{
    $html = null;
    $html = '<table class="tablecontent">';
    $html .= '<thead><tr>';
    $html .= '<th class="tablehead">Product</th>';
    $html .= '<th class="tablehead">Category</th>';
    $html .= '<th class="tablehead">Price</th>';
    $html .= '<th class="tablehead">Description</th>';
    $html .= '</tr></thead>';
    foreach ($tabledata as $product) {
        $html .= '<tbody><tr>';
        $html .= '<td class="tablebody">' . $product['productname'] . '</td>';
        $html .= '<td class="tablebody">' . $product['category'] . '</td>';
Example #2
0
$category = new Category($db);
$product_image = new ProductImage($db);
$product_pdf = new ProductPdf($db);
// set page title
$page_title = "Active Products";
// include page header HTML
include 'layout_head.php';
// get parameter values, and to prevent undefined index notice
$action = isset($_GET['action']) ? $_GET['action'] : "";
// tell the user he's already logged in
if ($action == 'already_logged_in') {
    echo "<div class='alert alert-info'>";
    echo "<strong>You</strong> are already logged in.";
    echo "</div>";
} else {
    if ($action == 'logged_in_as_admin') {
        echo "<div class='alert alert-info'>";
        echo "<strong>You</strong> are logged in as admin.";
        echo "</div>";
    }
}
// read all active products in the database
$stmt = $product->readAll($from_record_num, $records_per_page);
// count number of products returned
$num = $stmt->rowCount();
// to identify page for paging
$page_url = "read_products.php?";
// include products table HTML template
include_once "read_products_template.php";
// include page footer HTML
include_once 'layout_foot.php';
Example #3
0
<?php

// include database and object files
include_once '../config/database.php';
include_once '../objects/courses.php';
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();
// initialize object
$product = new Product($db);
// query products
$stmt = $product->readAll();
$num = $stmt->rowCount();
// check if more than 0 record found
if ($num > 0) {
    // start table
    echo "<table class='table table-bordered table-hover'>";
    // creating our table heading
    echo "<tr>";
    echo "<th class='width-30-pct'>Course Name</th>";
    echo "<th class='width-30-pct'>Course Description</th>";
    echo "<th>Price</th>";
    echo "<th>SKU</th>";
    echo "<th class='width-30-pct'>Course Image</th>";
    echo "<th style='text-align:center;'>Action</th>";
    echo "</tr>";
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        // extract row