From f83242e7ae7b051ab61b679b57e102fcf8e9b915 Mon Sep 17 00:00:00 2001 From: Joshua Perry <45966243+jpez-development@users.noreply.github.com> Date: Tue, 15 Nov 2022 15:38:46 +0000 Subject: [PATCH] fully populated listings by db --- public/listing.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/public/listing.php b/public/listing.php index 86b510a..96e072b 100644 --- a/public/listing.php +++ b/public/listing.php @@ -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 = ' product name

'. $listing['listing_name'] .'

-

'. $listing['listing_category'] .'

-

Auction created by User.Name

-

Current bid: £123.45

+

'. $category['category_name'] .'

+

Auction created by '. $user['first_name'].$user['last_name'] .'

+

Current bid: '. $bid['MAX(amount)'] .'