84043/Week10/alltables.php
/**
* Allows one to view all tables and their data in a database
*/
require_once("conn.php");
$sql = "SHOW TABLES";
$tables = $dbConn->query($sql);
$tablesAndTheirData = array();
while($tableName = $tables->fetch_array()) {
$sql = "SELECT * FROM $tableName[0] limit 100";
$data = $dbConn->query($sql);
array_push($tablesAndTheirData, array(
'name' => $tableName[0],
'fields' => $data->fetch_fields(),
'data' => $data
));
}
?>
Database Tables
Table
num_rows):?>
name;?> |
fetch_assoc()): ?>
$value):?>
|
Table does not have any data
$dbConn->close();
?>
84043/Week10/conn.php
$dbConn = new mysqli("localhost", "TWA_student", "TWA_2021_Autumn", "electrical");
if($dbConn->connect_error) {
die("Failed to connect to database " . $dbConn->connect_error);
}
?>
84043/Week10/Exercise1.php
query($sql)
or die ('Problem with query: ' . $dbConn->error);
?>
Product table
Product Code Name Quantity In Stock Price
fetch_assoc()) { ?>
close(); ?>
84043/Week10/Exercise3.php
10 ORDER BY quantityInStock asc";
$results = $dbConn->query($sql)
or die ('Problem with query: ' . $dbConn->error);
?>
Products with stock > 10
Name Quantity In Stock Price
fetch_assoc()) { ?>
close(); ?>
84043/Week10/exercise4.html
Quantity in Stock
Please enter the quantity to check against stock levels
Quantity:
84043/Week10/Exercise4.php
".$qty." ORDER BY quantityInStock asc";
$results = $dbConn->query($sql);
if(mysqli_num_rows($results) > 0){
$error='';
}else{
$error ="There are no products that have more than ".$qty." in stock";
}
}else{
$error ="The value entered for the quantity was not a number";
}
?>
Products with stock >
Name Quantity In Stock Price
fetch_assoc()) { ?>
close();
}
?>
...