Exemple #1
0
$result = $conn->query($sql) or die(mysqli_error());
//set up array to store the results of the lookup table query
$types = array();
while ($row = $result->fetch_assoc()) {
    //loop through the sql result, add each product_id and type_id to array to use later
    $types[] = array('product_id' => $row['product_id'], 'type_id' => $row['type_id'], 'type_name' => $row['type_name'], 'product_price' => $row['product_price']);
}
//now that we are finished with the types set, release the db resources to allow a new query.
$result->free_result();
////////////////////////////////////
//count number of products
$sql = "SELECT * FROM product\n                    LEFT JOIN image\n                    ON product.product_id = image.product_id";
//submit the SQL query to the database and get the result
$result = $conn->query($sql) or die(mysqli_error());
// set up navbar
$navbar = create_navbar($start_number, $items_per_page, $result->num_rows);
$result->free_result();
//get product info from  product and image tables
$sql = "SELECT * FROM product\n                    LEFT JOIN image\n                    ON product.product_id = image.product_id\n                    LIMIT {$start_number}, {$items_per_page}";
$result = $conn->query($sql) or die(mysqli_error());
while ($row = $result->fetch_assoc()) {
    //loop through the results of the product query and display product info.
    //Plus build the link dynamically to the details page
    echo '<div class="productt">';
    echo '<a href="product_details.php?product_id=' . $row['product_id'] . '"><img src="images/' . $row['thumb_filename'] . '" /></a>';
    echo '<p><a href="product_details.php?product_id=' . $row['product_id'] . ' "> ' . $row['product_name'] . '</a></p>';
    echo '<p class="price">Price: $' . $row['product_price'] . '</p>';
    echo '</div>';
}
//end of the while loop
//release the db resources to allow a new query
    while ($row = $result->fetch_assoc()) {
        $count = $row['count'];
    }
    #################################################
    ####Left Join for table information
    #################################################
    //set up SQL query
    $sql = "SELECT * FROM product\r\n\t\t\tLEFT JOIN esrb_rating \r\n\t\t\tON product.ESRB_id = esrb_rating.ESRB_rating_id\r\n\t\t\tLEFT JOIN image\r\n\t\t\tON product.main_image_id = image.image_id\r\n\t\t\tLEFT JOIN product_platform_lookup\r\n\t\t\tON product_platform_lookup.product_id = product.product_id\r\n\t\t\tWHERE product_platform_lookup.platform_id = 2\r\n\t\t\tLIMIT {$start_number}, {$items_per_page}";
    //submit the query and capture the result
    $result = $conn->query($sql) or die(mysqli_error());
    ###start if $result
    ?>
<div id="pagination">
<?php 
    if ($result->num_rows > 0) {
        $navbar = create_navbar($start_number, $items_per_page, $count);
        $category_sales .= "Data from SQL query";
        if (is_null($category_sales)) {
            echo "Invalid input.";
        } else {
            echo "{$navbar}<br />";
        }
        ?>
</div>
<div id="infoConfirm">
<?php 
        //check if conf set, and printout if so, if not, do nothing - this prevents an "undeclared variable" error
        //confirmation message code unset after used so not displayed on other pages
        if (isset($conf_msg)) {
            echo '<p class="' . $class . '">' . $conf_msg . '</p>';
            unset($_SESSION['conf_msg']);
function ISBN()
{
    include "/php/dbinfo.inc.php";
    mysql_connect('localhost', $username, $password);
    @mysql_select_db("ebooks") or die("Unable to select database");
    include 'previous_next_links.php';
    $start_number = intval($_GET["start"]);
    $items_per_page = 100;
    $where_clause = 1;
    $table = 'all_books';
    if ($start_number >= 0) {
        //count the items in the category
        $sql = "SELECT count(*) AS count FROM '{$table}' WHERE '{$where_clause}'";
        $result = @mysql_query($sql);
        while ($row = mysql_fetch_array($result)) {
            $count = $row['count'];
        }
        //end while loop
        //now get the results to show to the users
        $sql = "SELECT product_id, product_name FROM '{$table}' WHERE '{$where_clause}' LIMIT {$start_number} {$items_per_page}";
        $result = mysql_query($sql);
        if (mysql_num_rows($results) > 0) {
            while ($row = mysql_fetch_array($reuslt)) {
                //loop through and add HTML
                //into $$where_clause
                $where_clause .= "Datafrom SQL Query";
            }
            //end while loop
        } else {
            $where_clause = "There were no items found!";
        }
        $navbar = create_navbar($start_number, $items_per_page, $count);
    }
    //end if stmt
    if (is_null($where_clause)) {
        echo 'Invalid Input!';
    } else {
        echo "{$navbar}<br />{$where_clause}";
    }
}