Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title></title>
- </head>
- <body style="background-color:#999">
- <h1></h1>
- <form action="index.php" method="POST">
- <label for="games">Chose a game</label>
- <select name="games" id="games">
- <option value="1">EA</option>
- <option value="2">Frontier</option>
- <option value="3">Ubisoft</option>
- <option value="4">Microsoft</option>
- </select>
- <input type="submit" value="Search">
- </form>
- <?php
- // 1.) Gewähltes Game abfragen $_POST / $_GET
- // check, if entry in post exists - with 'isset' or !empty
- if (isset($_POST['games'])) {
- $games = $_POST['games']; // $_POST weil method=POST, 'game' weil name="game"
- echo "Game ($games)<br>";
- }
- $dbserver = "localhost";
- $dbuser = "root";
- $dbpass = "";
- $dbname = "productdb";
- if (!empty($games)) {
- // Create connection
- $conn = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- echo "Connected successfully";
- // 2.) Game aus der Datenbank holen
- $sql = "SELECT idProduct, productBez, productPrice FROM product WHERE hersteller_idhersteller = $games;"; //
- $result = $conn->query($sql);
- // if results are found
- if ($result->num_rows > 0) {
- // if data available, then output
- echo '<table border="1" cellspacing="0" cellpadding="0">';
- echo '<tr><td>Game</td><td>Price</td><td>Properties</td></tr>';
- // 3.) game als Tabelle usgeben
- // output data of each row
- while($row = $result->fetch_assoc()) {
- #echo "ProductBez: " . $row["productBez"]. " - ProductPrice: " . $row["productPrice"]."<br>";
- // current product
- $product = $row['idProduct']; //
- // SubQuery for properties
- $sql = "SELECT propertiesBezeichnung, propertiesEinheit FROM properties
- INNER JOIN product_properties ON properties.idEigenschaften = product_properties.properties_idEigenschaften
- WHERE product_idProduct = $product;";
- // get properties
- $properties = "";
- $result2 = $conn->query($sql); // load
- if ($result2->num_rows > 0) { // if exist
- while($row2 = $result2->fetch_assoc()) {
- $properties .= $row2['propertiesBezeichnung'].":".$row2['propertiesEinheit']."<br>"; //
- } // END while result 2
- } // END if result2
- echo "<tr><td>" . $row["productBez"]. "</td></td>" .$row["productPrice"]."</td><td>".$properties."</td></tr>";
- }
- echo "</table>";
- } else { // if no results are found
- echo "No results found";
- }
- // 4.) clean up
- $conn->close();
- } // close if
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement