Permalink
Cannot retrieve contributors at this time
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?
DatabasesPhase2_GroupE/adminPages/Report_Sales.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (47 sloc)
2.52 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 * FROM `sales by category` WHERE CategoryID = ?"; //'?' in place of variable | |
$stmt = $con->prepare($query); | |
$stmt ->bind_param("d", $_GET['Category']); //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_Sales.php" method = "get"> | |
<h1>Sales Report</h1> | |
<div class="form-group"> | |
<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> | |
<input type="submit" value="View Report"> | |
</div> | |
</form> | |
<?php | |
} //Close bracket from 'else' above | |
?> | |
</div> | |
</body> | |
</html> |