Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // DATABASE CONNECTION
- // define login credentials for the database
- // these must match the settings on your database
- $username = "root";
- $password = "";
- $host = "localhost";
- $database = "ao16_dummy_database";
- $table = "averages_final";
- // connect to MySQL server
- // the function mysqli_connect(...) returns a link to the database which we store in the variable $link
- $link = mysqli_connect($host, $username, $password) or die("Connection to database server failed!");
- // NB: using die() is not the most elegant way to handle errors because it causes the site to only return
- // the error message, no styling and so on. A more elegant way would be to ensure the site keeps running
- // whenever possible and else print out errors in a more appealing page design ;)
- // select the database to work with
- mysqli_select_db($link, $database);
- // DATABASE ACCESS (read)
- // fetch all users from the database
- $result = mysqli_query($link, "SELECT * FROM $table");
- // SELECT * FROM $table is SQL syntax and means 'select everything from the table given and return it'
- echo "<table>\n";
- // go through each entry
- while ($data = mysqli_fetch_array($result))
- {
- // print the details
- echo "\t<tr>\n";
- echo "\t\t<td>" . $data['name'] . "</td>\n\t\t<td>" . $data['final'] . "</td>\n";
- echo "\t</tr>\n";
- // the echo keyword is used to output data to the browser, usually HTML
- // the while keyword denotes that this code is repeated as long as there is data ($data = mysqli_fetch_array($result))
- }
- echo "</table>\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement