fully populated listings by db

This commit is contained in:
Joshua Perry 2022-11-15 15:38:46 +00:00
parent 978753bfae
commit f83242e7ae
1 changed files with 25 additions and 4 deletions

View File

@ -14,20 +14,41 @@ function populateContent() {
$password = 'student';
$schema = 'ibuy';
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
$stmt = $pdo->prepare('SELECT * FROM listings 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');
$values = [
'category_id' => $listing['listing_category']
];
$stmt->execute($values);
$category = $stmt->fetch();
$stmt = $pdo->prepare('SELECT MAX(amount) FROM bids WHERE listing_id = :listing_id');
$values = [
'listing_id' => $listing['listing_id']
];
$stmt->execute($values);
$bid = $stmt->fetch();
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
$values = [
'email' => $listing['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>'. $listing['listing_category'] .'</h3>
<p>Auction created by <a href="#">User.Name</a></p>
<p class="price">Current bid: £123.45</p>
<h3>'. $category['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:'. (strtotime($listing['listing_deadline']) - strtotime(date('Y-m-d H:i:s')))/60 .'</time>
<form action="#" class="bid">
<input type="text" name="bid" placeholder="Enter bid amount" />