This is just a Shopping Cart tutorial and will not provide any real services.

Compass Programming

Here is the inventory

This page just shows the available inventory. All inventory quantity and names are placed into the product table with two other tables, see below, providing additional data.

Tables that are access for this page:

Creating a manufacturer and category table is important for consistency when dozens or hundreds of products are added to the shopping cart over time. Sometimes a comic book is labeled 'Comic Book' sometimes 'Comic' or maybe just 'book' all of those could produce different search results for checking inventory. This makes it consistant for all products.

At the bottom of the items is a way to have a limited number of items in this case 3 so the pagination can be demonstrated. I used this very helpful tutorial as a template By Paritosh Pandey at My Programming Tutorials for the pagination pages. I have one page called information.php that I use for all the statements that require table access. The only thing that changes is the first statement. For instance this is how finding a company in the search box appears:
/*find the company statement is on this page*/
$company = filter_input(INPUT_POST, 'company');
if ($company != ''){
$findProduct = 'SELECT p.productId,, p.image, p.description, p.price, p.quantity, p.manufacturerId, p.categoryId, m.manufacturerId, m.manufacturerName FROM product p, manufacturer m WHERE p.manufacturerId = m.manufacturerId AND = 1 AND m.manufacturerId = '.$company.' ORDER BY m.manufacturerName'; $shopper = 1;/*this is used to find the correct query on information.php page*/
include 'information.php'; } }

After performing the SELECT statement then it goes to the information.php page to perform the query to bring back the results. Notice above how I added the variable $shopper = 1, that is how the query is located in the information.php page. Here are the first few lines on what is on the information.php page:
/*All of this plus other functions/queries that I use multiple times are on this page*/
$paginationLimit = 'LIMIT '.$offset.', '.$pageLimit.'';
if ($shopper == 1){
$resultProduct = mysqli_query($databaseConnection, $findProduct);
if (!$resultProduct) {
printf("%s\n", $databaseConnection->error);
$rowCount = $resultProduct->num_rows;
$totalPages = ceil($rowCount / $pageLimit);
if ($rowCount >= 1) {
$paginationSQL = $findProduct.' '.$paginationLimit;
$resultPagination = mysqli_query($databaseConnection, $paginationSQL);
if (!$resultPagination) {
printf("%s\n", $databaseConnection->error);
while ($row = mysqli_fetch_array($resultPagination, MYSQLI_ASSOC)){/*continues onward*/
Then the rest of the code is run to come up with the results.

When asking for a user to enter information into a blank area make sure that you do some verification and assistance in looking for the searchable item.
if (isset($showResults)){
$customerStart = 0;
/*first looking for the general search typed in search*/
$search = filter_input(INPUT_POST, 'search');
$search = preg_replace('/[^a-zA-Z0-9]/', '', $search);/*removing any chance something could be injected into this box and passed into my code and database*/
if($search != ''){
$countLength = strlen($search);//making sure least 3 letters are entered for a good research
/*using the LIKE statement to find anything in the search criteria that are somewhat like the search criteria*/
if ($countLength >= 3){
$findProduct = 'SELECT p.productId,, p.image, p.description, p.price, p.quantity, p.manufacturerId, p.categoryId, m.manufacturerId, m.manufacturerName FROM product p, manufacturer m WHERE p.manufacturerId = m.manufacturerId AND = 1 AND LIKE "%'.$search.'%" ORDER BY m.manufacturerName';
$shopper = 1;
include 'information.php';
$moreLetters .= 'Please enter at least 3 letters into search';
}/*incomplete code just showing excerpt*/

I have also added a way to view the cart in a vertical configuration in case you are selling a large number of similar items that need very little explaination and can be shown mainly as a visual item. I have changed the page to see all items so that you have a good visualization of how the vertically display looks. I opted for a very simple way of doing this by having a form send a fixed value:
<form id='findArticle' action='shop' method='post' >
<input name='horizontalInv' id='horizontalInv' value=1 type='hidden'>
<input name='gridFormat' id='gridFormat' value='Show in Grid' type='submit' class='allLookup'>
The value is 1 for showing the grid and value is 0 when going back to the vertical view.

Need to find something more specific:

300 - Dark Horse
$20.00 (3 Available)
Frank Miller and Dark Horse Comics - The armies of Persia—a vast horde greater than any the world has ever known—are poised to crush Greece, an island...

Batman Versus Predator - DC
$3.50 (292 Available)
Batman Versus Predator- Book 2 of 3

The Savage Dragon issue 1 - Image
$1.75 (287 Available)
The Savage Dragon issue 1, white outline

There are 9 products on 3 page(s)

1 of 3

All products on this website for tutorial purposes only. No real transactions are conducted on this shopping cart tutorial. Last Update to these pages was 13 April 2020

Questions or comments please send them to josh(at) Thank you!

Compass Programming LLC all rights reserved 2020

Return to Compass Programming home page.