made code constrained to brief db spec

This commit is contained in:
Joshua Perry 2022-11-16 19:17:35 +00:00
parent 8c29f52051
commit 88aebe81ac
4 changed files with 15 additions and 15 deletions

2
db.php
View File

@ -5,7 +5,7 @@ function fetchCats() {
$password = 'student';
$schema = 'ibuy';
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
$stmt = $pdo->prepare('SELECT * FROM categories');
$stmt = $pdo->prepare('SELECT * FROM category');
$stmt->execute();
$cats = $stmt->fetchAll();

View File

@ -36,7 +36,7 @@ require_once 'db.php';
<?php
$cats = fetchCats();
foreach ($cats as &$cat) {
echo '<li><a class="categoryLink" href="../index.php?pageHeading='. urlencode($cat['category_name']) .'">'. $cat['category_name'] .'</a></li>';
echo '<li><a class="categoryLink" href="../index.php?pageHeading='. urlencode($cat['name']) .'">'. $cat['name'] .'</a></li>';
}
?>
<li><a class="categoryLink" <?php echo $logButton?></a></li>

View File

@ -25,12 +25,12 @@ function populateList($category) { //TODO: This will need to be updated to popul
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
if ($category === 'Latest Listings') {
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_deadline > "'. date("Y-m-d H:i:s"). '" ORDER BY listing_deadline DESC');
$stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate DESC');
$stmt->execute();
$listings = $stmt->fetchAll();
}
else {
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_category = (SELECT category_id FROM categories WHERE category_name = :listing_category)');
$stmt = $pdo->prepare('SELECT * FROM auction WHERE categoryId = (SELECT category_id FROM category WHERE name = :listing_category)');
$values = [
'listing_category' => $category
];
@ -48,9 +48,9 @@ function populateList($category) { //TODO: This will need to be updated to popul
$output .= '<li>
<img src="assets/product.png" alt="product name">
<article>
<h2>'. $listing['listing_name'] .'</h2>
<h3>'. $listing['listing_category'] .'</h3>
<p>'. $listing['listing_description'] .'</p>
<h2>'. $listing['name'] .'</h2>
<h3>'. $listing['categoryId'] .'</h3>
<p>'. $listing['description'] .'</p>
<p class="price">Current bid:'. $stmt->fetch()['MAX(amount)'] .'</p>
<a href="listing.php?listing_id='. $listing['listing_id'] .'" class="more auctionLink">More &gt;&gt;</a>
</article>

View File

@ -14,16 +14,16 @@ function populateContent() {
$schema = 'ibuy';
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
$stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_id= :listing_id');
$stmt = $pdo->prepare('SELECT * FROM auction WHERE listing_id= :listing_id');
$values = [
'listing_id' => $_GET['listing_id']
];
$stmt->execute($values);
$listing = $stmt->fetch();
$stmt = $pdo->prepare('SELECT * FROM categories WHERE category_id = :category_id');
$stmt = $pdo->prepare('SELECT * FROM category WHERE category_id = :category_id');
$values = [
'category_id' => $listing['listing_category']
'category_id' => $listing['categoryId']
];
$stmt->execute($values);
$category = $stmt->fetch();
@ -37,25 +37,25 @@ function populateContent() {
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
$values = [
'email' => $listing['listing_email']
'email' => $listing['email']
];
$stmt->execute($values);
$user = $stmt->fetch();
$output = ' <img src="product.png" alt="product name">
<section class="details">
<h2>'. $listing['listing_name'] .'</h2>
<h3>'. $category['category_name'] .'</h3>
<h2>'. $listing['name'] .'</h2>
<h3>'. $category['name'] .'</h3>
<p>Auction created by <a href="#">'. $user['first_name'].$user['last_name'] .'</a></p>
<p class="price">Current bid: '. $bid['MAX(amount)'] .'</p>
<time>Time left:'. round((strtotime($listing['listing_deadline']) - strtotime(date('Y-m-d H:i:s')))/60,1 ) .' Minutes</time>
<time>Time left:'. round((strtotime($listing['endDate']) - strtotime(date('Y-m-d H:i:s')))/60,1 ) .' Minutes</time>
<form action="#" class="bid">
<input type="text" name="bid" placeholder="Enter bid amount" />
<input type="submit" value="Place bid" />
</form>
</section>
<section class="description">
<p>'. $listing['listing_description'] .'</p>
<p>'. $listing['description'] .'</p>
</section>