diff --git a/public/index.php b/public/index.php index aed9c78..689895d 100644 --- a/public/index.php +++ b/public/index.php @@ -12,23 +12,52 @@ else { } $pageContent = '

'.$pageHeading.'

-'; +'; require '../layout.php'; -function populateList() { //TODO: This will need to be updated to populate from the database +function populateList($category) { //TODO: This will need to be updated to populate from the database $output = ''; - for ($i = 0; $i <= 10; $i++) { + $server = 'mysql'; + $username = 'student'; + $password = 'student'; + $schema = 'ibuy'; + $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->execute(); + $listings = $stmt->fetchAll(); + } + else { + $stmt = $pdo->prepare('SELECT * FROM listings WHERE listing_category = :listing_category'); + $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); + $output .= '
  • product name
    -

    Product name

    -

    Product category

    -

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sodales ornare purus, non laoreet dolor sagittis id. Vestibulum lobortis laoreet nibh, eu luctus purus volutpat sit amet. Proin nec iaculis nulla. Vivamus nec tempus quam, sed dapibus massa. Etiam metus nunc, cursus vitae ex nec, scelerisque dapibus eros. Donec ac diam a ipsum accumsan aliquet non quis orci. Etiam in sapien non erat dapibus rhoncus porta at lorem. Suspendisse est urna, egestas ut purus quis, facilisis porta tellus. Pellentesque luctus dolor ut quam luctus, nec porttitor risus dictum. Aliquam sed arcu vehicula, tempor velit consectetur, feugiat mauris. Sed non pellentesque quam. Integer in tempus enim.

    -

    Current bid: £123.45

    - More >> +

    '. $listing['listing_name'] .'

    +

    '. $listing['listing_category'] .'

    +

    '. $listing['listing_description'] .'

    +

    Current bid:'. $stmt->fetch() .'

    + More >>
    -
  • '; + '; } + + + return $output; } ?> \ No newline at end of file