Skip to content

Instantly share code, notes, and snippets.

@lennondtps
Created February 19, 2013 20:07
Show Gist options
  • Save lennondtps/4989423 to your computer and use it in GitHub Desktop.
Save lennondtps/4989423 to your computer and use it in GitHub Desktop.
<?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