Skip to content
Permalink
ae335aeb5c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
92 lines (78 sloc) 4.41 KB
<?php
require("../dbCon.php");
require("../commonFunctions.php");
?>
<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuAdm("Reports.php"); ?>
</div>
<div id='contentwrapper'>
<?php
if (isset($_GET['Category'])){ //Check if category has already been set
$query = "SELECT p.ProductName, cat.CategoryName, p.UnitsInStock, cp.CompanyName as `Supplier's Name`
FROM (((products p LEFT JOIN suppliers s ON p.SupplierID = s.SupplierID)
LEFT JOIN company cp ON s.CompanyID = cp.CompanyID)
LEFT JOIN categories cat ON p.CategoryID = cat.CategoryID)
WHERE cat.CategoryID = ?
AND cp.CompanyName LIKE ?
AND p.ProductName LIKE ?
AND ? <= p.UnitsInStock AND p.UnitsInStock <= ?
" ; //'?' in place of variable
$ProductName = "%" . $_GET['ProductName'] . "%";
$SupplierName = "%" . $_GET['SupplierName'] . "%";
//stock ranges
if (empty($_GET["InStockStart"])){
$InStockStart = 0;
}else{
$InStockStart = $_GET['InStockStart'];
}
if (empty($_GET["InStockEnd"])){
$InStockEnd = 102984573293485490;
}else{
$InStockEnd = $_GET['InStockEnd'];
}
$stmt = $con->prepare($query);
$stmt ->bind_param("dssdd", $_GET['Category'], $SupplierName, $ProductName, $InStockStart,
$InStockEnd); //Bind category to query, category is taken in as CategoryID, so it's a digit
$stmt ->execute();
$searchResult = $stmt->get_result(); //Get results
makeTable($searchResult); //Make table from results, makeTable code is in commonFunctions.php
}else{ //If category has not been set, show HTML form to pick category
?>
<form action = "Report_Inventory.php" method = "get">
<h1>Inventory Report</h1>
<div class="form-group">
<!--category stuff-->
<label>Select Product Category</label>
<select name="Category" id="Category">
<?php //Populate category drop down by getting categories from DB
$query ="SELECT * FROM categories"; //Query
$stmt = $con->prepare($query); //'con' is name of DB connection, defined in dbCon.php (which is loaded at the top of this file)
$stmt ->execute(); //Run query
$result = $stmt->get_result(); //Put query results into $results array
while($row = mysqli_fetch_array($result)) { //Iterate through each row of results
echo "<option value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>"; //'echo' outputs the given line to the HTML, so this creates a new row in the drop-down for each category
}
?>
</select>
<label>Product Name</label>
<input type="text" name="ProductName" id="ProductName">
<label>Supplier's Name</label>
<input type="text" name="SupplierName" id="SupplierName">
<label>In Stock: Start</label>
<input type="text" name="InStockStart" id="InStockStart">
<label>In Stock: End</label>
<input type="text" name="InStockEnd" id="InStockEnd">
<input type="submit" value="View Report">
</div>
</form>
<?php
} //Close bracket from 'else' above
?>
</div>
</body>
</html>