-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.php
65 lines (57 loc) · 2.23 KB
/
read.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once("session.php");
require_once("included_functions.php");
require_once("database.php");
new_header("GalleryGrove 2023");
$mysqli = Database::dbConnect();
$mysqli->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (($output = message()) !== null) {
echo $output;
}
$query = "SELECT a.artId, a.title, CONCAT(ar.fName, ' ', ar.lName) AS artist, a.description, a.price,
GROUP_CONCAT(DISTINCT g.name ORDER BY g.name SEPARATOR ',') AS genre
FROM Art_Genre ag
JOIN Genre g ON ag.genreId = g.genreId
JOIN Arts a ON ag.artId = a.artId
JOIN Artist ar ON a.artistId = ar.artistId
GROUP BY a.artId, a.title, artist, a.description, a.price
ORDER BY a.artId ASC;";
$stmt = $mysqli->prepare($query);
$stmt->execute();
if ($stmt) {
echo "<div class='row'>";
echo "<center>";
echo "<h2>GalleryGrove</h2>";
echo "<table>";
echo "<thead>";
echo "<tr><th>Artist</th><th>Genre</th><th>Title</th><th>Description</th><th>Price</th></tr>";
echo "</thead>";
echo "<tbody>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$artist = $row['artist'];
$title = $row['title'];
$description = $row['description'];
$price = $row['price'];
$genre = $row['genre'];
echo "<tr>";
echo "<td><a href='delete.php?id=".urlencode($row['artId'])."' onclick='return confirm(\"Are you sure want to delete?\");' style='color:red;'>X</a></td>";
echo "<td>{$artist}</td>";
echo "<td>{$genre}</td>";
echo "<td>{$title}</td>";
echo "<td>{$description}</td>";
echo "<td>$" . number_format($price, 2) . "</td>";
echo "<td><a href='update.php?id=".urlencode($row['artId'])."'>Edit</a></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<p><a href='create.php'>Add a new art piece</a></p>";
echo "<a href='read1.php'>More Art Details</a>";
echo "</center>";
echo "</div>";
} else {
echo "Error: " . $mysqli->error;
}
new_footer("GalleryGrove");
Database::dbDisconnect($mysqli);
?>