This commit is contained in:
Joshua Perry 2022-11-20 17:51:10 +00:00
parent fb76234eb8
commit a90bda3896
2 changed files with 14 additions and 4 deletions

View File

@ -18,12 +18,13 @@ $pageContent = '<h1>Edit Auction</h1>
require '../../layout.php'; require '../../layout.php';
if(isset($_POST['submit'])) { if(isset($_POST['submit'])) {
$stmt = $pdo->prepare('UPDATE auction SET title = :title, categoryId = :categoryId, endDate = :endDate, description = :description'); $stmt = $pdo->prepare('UPDATE auction SET title = :title, categoryId = :categoryId, endDate = :endDate, description = :description WHERE listing_id = :listing_id');
$values = [ $values = [
'title' => $_POST['title'], 'title' => $_POST['title'],
'categoryId' => intval($_POST['category']), 'categoryId' => intval($_POST['category']),
'endDate' => $_POST['endDate'], 'endDate' => $_POST['endDate'],
'description' => $_POST['description'] 'description' => $_POST['description'],
'listing_id' => $listing['listing_id']
]; ];
$stmt->execute($values); $stmt->execute($values);
echo '<script>window.location.href = "../listing.php?listing_id='.$listing['listing_id'].'";</script>'; echo '<script>window.location.href = "../listing.php?listing_id='.$listing['listing_id'].'";</script>';

View File

@ -21,7 +21,7 @@ function populateList($category) {
$pdo = startDB(); $pdo = startDB();
$output = ''; $output = '';
if ($category === 'Latest Listings') { if ($category === 'Latest Listings') {
$stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate DESC'); $stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate ASC');
$stmt->execute(); $stmt->execute();
$listings = $stmt->fetchAll(); $listings = $stmt->fetchAll();
} }
@ -35,6 +35,15 @@ function populateList($category) {
} }
foreach ($listings as &$listing) { foreach ($listings as &$listing) {
$stmt = $pdo->prepare('SELECT * FROM category WHERE category_id = :category_id');
$values = [
'category_id' => $listing['categoryId']
];
$stmt->execute($values);
$listCat = $stmt->fetch()['name'];
$stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id'); $stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id');
$values = [ $values = [
'listing_id' => $listing['listing_id'] 'listing_id' => $listing['listing_id']
@ -45,7 +54,7 @@ function populateList($category) {
<img src="assets/product.png" alt="product name"> <img src="assets/product.png" alt="product name">
<article> <article>
<h2>'. $listing['title'] .'</h2> <h2>'. $listing['title'] .'</h2>
<h3>'. $listing['categoryId'] .'</h3> <h3>'. $listCat .'</h3>
<p>'. $listing['description'] .'</p> <p>'. $listing['description'] .'</p>
<p class="price">Current bid:'. $stmt->fetch()['MAX(amount)'] .'</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> <a href="listing.php?listing_id='. $listing['listing_id'] .'" class="more auctionLink">More &gt;&gt;</a>