Output

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1 <?

php
2 require 'db_connection.php';
3
4 //Gets all games sorted by title
5 function getGames() {
6 global $dbConn;
7 $sql = "SELECT * FROM games_info ORDER BY gameTitle";
8 $stmt = $dbConn -> prepare($sql);
9 $stmt -> execute();
10 return $stmt->fetchAll();
11 }
12
13 //Gets list from table. Takes a table and a heading to sort as arguments
14 function getList($table, $headingName) {
15 global $dbConn;
16 $sql = "SELECT * FROM $table ORDER BY $headingName";
17 $stmt = $dbConn -> prepare($sql);
18 $stmt -> execute();
19 return $stmt->fetchAll();
20 }
21
22 //Filter games. First parameter defines the filter category and second
paramenter defines value to compare.
23 function filterGames($filter, $value) {
24 global $dbConn;
25 $sql = "SELECT * FROM games_info WHERE $filter = :value";
26 $stmt = $dbConn -> prepare($sql);
27 $stmt -> execute(array(':value' => $value));
28 return $stmt->fetchAll();
29 }
30
31 function getGame($gameId){
32 global $dbConn;
33 $sql = "SELECT * FROM games_info WHERE gameId = :gameId";
34 $stmt = $dbConn -> prepare($sql);
35 $stmt -> execute(array(":gameId"=>$gameId));
36 return $stmt->fetch();
37 }
38
39 //Gets piblishers, genres and ratings
40 $gamePublishers = getList('game_publishers', 'publisherName');
41 $gameGenres = getList('game_genres','genreName');
42 $gameRatings = getList('game_ratings', 'ratingName');
43
44 //Checks which filter button was submitted and gets appropriate list
45 if (isset($_POST['filterGenre'])) {
46 $gameNames = filterGames('gameGenre', $_POST['genreId']);
47 } elseif (isset($_POST['filterPublisher'])) {
48 $gameNames = filterGames('gamePublisher', $_POST['publisherId']);
49 } elseif (isset($_POST['filterRatings'])) {
50 $gameNames = filterGames('gameRating', $_POST['ratingId']);
51 } else {
52 $gameNames = getGames();
53 }
54 ?>
55
56 <!DOCTYPE html>
57 <html lang="en">
58 <head>
59 <title>new_file</title>
60 <link rel="stylesheet" type="text/css" href="main.css" />
61 </head>
62 <body>
63 <div id="wrapper">
64 <header>
65 <form method="post" action="logout.php">
66 <input type="submit" value="Logout"/>
67 </form>
68 <form method="post" action="update_db.php">
69 <input type="submit" value="Update"/>
70 </form>
71 <h1>Game Stop</h1>
72 </header>
73 <nav>
74 <form method="POST">
75 <select name="genreId">
76 <option value="-1">- Select Genre</option>
77 <?php
78 foreach ($gameGenres as $genre) {
79 echo "<option value=\"" . $genre['genreId'] . "\">"
. $genre['genreName'] . "</option>";
80 }
81 ?>
82 </select>
83 <input type="submit" name="filterGenre" value="Filter" />
84 <select name="publisherId">
85 <option value="-1">- Select Publisher</option>
86 <?php
87 foreach ($gamePublishers as $publisher) {
88 echo "<option value=\"" . $publisher['publisherId']
. "\">" . $publisher['publisherName'] . "</option>";
89 }
90 ?>
91 </select>
92 <input type="submit" name="filterPublisher" value="Filter" />
93 <select name="ratingId">
94 <option value="-1">- Select Rating</option>
95 <?php
96 foreach ($gameRatings as $rating) {
97 echo "<option value=\"" . $rating['ratingId'] .
"\">" . $rating['ratingName'] . "</option>";
98 }
99 ?>
100 </select>
101 <input type="submit" name="filterRatings" value="Filter" />
102 <input type="submit" name="clearFilter" value="Clear Filter" />
103 </form>
104 </nav>
105 <?php
106 if (isset($_POST['moreInfo'])) {
107 $gameInfo = getGame($_POST['gameId']);
108 echo "<div id=\"moreInfoPanel\">";
109 echo "<img src = \"_images\\_boxart\\case.png\" class =
\"gameArt\" height = \"295px\" width = \"225px\">";
110 echo "<h5>". $gameInfo['gameTitle'] . "</h5>";
111 echo "<p>". $gameInfo['gameTitle'] . "</p>";
112 echo "<p>". $gameInfo['gameTitle'] . "</p>";
113 echo "<a href=\"index.php\">Close More Info</a>";
114 echo "</div>";
115 }
116 ?>
117 <div id="gamesList">
118 <?php
119 foreach ($gameNames as $game) {
120 echo "<div class=\"gameProfile\">";
121 echo "<img src = \"_images\\_boxart\\" . $game['gameId']
. ".jpg\" class = \"gameArt\" height = \"190px\" width =
\"150px\">";
122 echo "<h5>". $game['gameTitle'] . "</h5>";
123 echo "<p>". $game['gamePrice'] . "</p>";
124 echo "<form method=\"POST\">";
125 echo "<input type=\"submit\" name=\"moreInfo\"
value=\"More Info\"/>";
126 echo "<input type=\"hidden\" name=\"gameId\"
value=\"" . $game['gameId'] . "\"/>";
127 echo "</form>";
128 echo "</div>";
129 }
130 ?>
131 </div>
132 </div>
133 </body>
134 </html>

You might also like