2022-10-22 15:03:47 +00:00
|
|
|
<?php
|
2022-11-16 13:27:51 +00:00
|
|
|
session_start();
|
2022-10-22 15:03:47 +00:00
|
|
|
//Listing display page. Display the 10 auctions finishing soonest
|
|
|
|
|
//Can be used for index, search page, and category listing
|
|
|
|
|
$pageTitle = 'iBuy - Home';
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['pageHeading'])) {
|
|
|
|
|
$pageHeading = $_GET['pageHeading'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$pageHeading = 'Latest Listings';
|
|
|
|
|
}
|
2022-11-20 13:20:58 +00:00
|
|
|
require_once '../functions.php';
|
2022-10-22 15:03:47 +00:00
|
|
|
|
|
|
|
|
$pageContent = '<h1>'.$pageHeading.'</h1>
|
2022-11-15 14:32:51 +00:00
|
|
|
<ul class="productList">'.populateList($pageHeading).'</ul>';
|
2022-10-22 15:03:47 +00:00
|
|
|
require '../layout.php';
|
|
|
|
|
|
2022-11-19 14:58:22 +00:00
|
|
|
function populateList($category) {
|
2022-11-20 13:20:58 +00:00
|
|
|
$pdo = startDB();
|
2022-10-22 15:03:47 +00:00
|
|
|
$output = '';
|
2022-11-15 14:32:51 +00:00
|
|
|
if ($category === 'Latest Listings') {
|
2022-11-16 19:17:35 +00:00
|
|
|
$stmt = $pdo->prepare('SELECT * FROM auction WHERE endDate > "'. date("Y-m-d H:i:s"). '" ORDER BY endDate DESC');
|
2022-11-15 14:32:51 +00:00
|
|
|
$stmt->execute();
|
|
|
|
|
$listings = $stmt->fetchAll();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-11-16 19:17:35 +00:00
|
|
|
$stmt = $pdo->prepare('SELECT * FROM auction WHERE categoryId = (SELECT category_id FROM category WHERE name = :listing_category)');
|
2022-11-15 14:32:51 +00:00
|
|
|
$values = [
|
|
|
|
|
'listing_category' => $category
|
|
|
|
|
];
|
|
|
|
|
$stmt->execute($values);
|
|
|
|
|
$listings = $stmt->fetchAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($listings as &$listing) {
|
|
|
|
|
$stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id');
|
|
|
|
|
$values = [
|
|
|
|
|
'listing_id' => $listing['listing_id']
|
|
|
|
|
];
|
|
|
|
|
$stmt->execute($values);
|
|
|
|
|
|
2022-10-22 15:03:47 +00:00
|
|
|
$output .= '<li>
|
|
|
|
|
<img src="assets/product.png" alt="product name">
|
|
|
|
|
<article>
|
2022-11-16 19:25:32 +00:00
|
|
|
<h2>'. $listing['title'] .'</h2>
|
2022-11-16 19:17:35 +00:00
|
|
|
<h3>'. $listing['categoryId'] .'</h3>
|
|
|
|
|
<p>'. $listing['description'] .'</p>
|
2022-11-15 15:43:46 +00:00
|
|
|
<p class="price">Current bid:'. $stmt->fetch()['MAX(amount)'] .'</p>
|
2022-11-15 14:32:51 +00:00
|
|
|
<a href="listing.php?listing_id='. $listing['listing_id'] .'" class="more auctionLink">More >></a>
|
2022-10-22 15:03:47 +00:00
|
|
|
</article>
|
2022-11-15 14:32:51 +00:00
|
|
|
</li>';
|
2022-10-22 15:03:47 +00:00
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
?>
|