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:
- manufacturer - Created for company names
- category - Created to name specific categories in this case comic books, board games, etc
- product - Contains all of the items for sale and their quantities
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 https://www.myprogrammingtutorials.com/create-pagination-with-php-and-mysql.html 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.name, 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 m.active = 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*/
Then the rest of the code is run to come up with the results.
$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*/
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.name, 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 m.active = 1 AND p.name LIKE "%'.$search.'%" ORDER BY m.manufacturerName';
$shopper = 1;
include 'information.php';
}else{
$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' >
The value is 1 for showing the grid and value is 0 when going back to the vertical view.
<input name='horizontalInv' id='horizontalInv' value=1 type='hidden'>
<input name='gridFormat' id='gridFormat' value='Show in Grid' type='submit' class='allLookup'>
</form>
Need to find something more specific:
Venom- The Mace Conclusion - Marvel
$4.50 (299 Available)
Venom vs The Mace the Conclusion
Rubiks Cube - Rubiks
$10.00 (292 Available)
Rubiks Cube
Gammarauders - TSR
$20.00 (93 Available)
Gammarauders board Game