Created
February 19, 2013 20:07
-
-
Save lennondtps/4989423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$username = "root"; | |
$password = ""; | |
$hostname = "localhost"; | |
//connection to the database | |
$con = mysql_connect($hostname, $username, $password) | |
or die("Unable to connect to MySQL"); | |
//select a database to work with | |
$selected = mysql_select_db("grades_db",$con) | |
or die("Could not select examples"); | |
//execute the SQL query and return records | |
$result = mysql_query("SELECT Name,Surname,Grade FROM grades ORDER BY Grade"); | |
$max = mysql_query("SELECT MAX( Grade )FROM grades"); | |
$min = mysql_query("SELECT MIN( Grade )FROM grades"); | |
$avg = mysql_query("SELECT AVG( Grade )FROM grades"); | |
//fetch tha data from the database | |
while ($row = mysql_fetch_array($result)) { | |
printf("%s %s %s %s %s </br>", $row["Name"], $row["Surname"], $row["Grade"] - $max, $row["Grade"] - $min, $row["Grade"] - $avg); | |
} | |
//close the connection | |
mysql_close($con); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment