-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_data.php
35 lines (27 loc) · 971 Bytes
/
index_data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
header('Content-Type: application/json');
$servername = "localhost";
$username = "phpmyadmin";
$password = "Marketplace18";
$dbname = "marketplace";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die(json_encode(['error' => 'Connection failed: ' . $conn->connect_error]));
}
$data = [
'listings' => [],
'auctions' => [],
'giveaways' => [],
];
// Fetch Listings
$result = $conn->query("SELECT * FROM listingData ORDER BY ListingId DESC LIMIT 4");
if ($result) $data['listings'] = $result->fetch_all(MYSQLI_ASSOC);
// Fetch Auctions
$result = $conn->query("SELECT * FROM auctionsData ORDER BY id DESC LIMIT 4");
if ($result) $data['auctions'] = $result->fetch_all(MYSQLI_ASSOC);
// Fetch Giveaways
$result = $conn->query("SELECT * FROM giveawayData ORDER BY giveaway_id DESC LIMIT 4");
if ($result) $data['giveaways'] = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode($data);
$conn->close();
?>