Turner's MySQL Exercise Source Code
From Humanitarian-FOSS Project Development Site
classlist.php
<html> <title>CPSC225 Class List</title> <body> <?php function showerror() { die("Error " . mysql_errno() . " : " . mysql_error()); } /** * This function creates the connection to the specified database. * * @author Turner Hayes * @param string $db * */ function db_connect($db) { if (!($connection = @ mysql_connect("localhost","root",""))) die("Could not connect"); if (!(@ mysql_select_db($db, $connection))) showerror(); } db_connect('sahana'); $sql = "SELECT DISTINCT 'm'.'name' AS 'Name', 'm'.'email' AS 'Email', 'm'.'role' AS 'Role', 't'.'team_name' AS 'Team Name', 's'.'name' AS 'School' 's'.'city' AS 'City', 's'.'state' AS 'State' FROM 'members' AS 'm', 'teams' AS 't', 'schools' AS 's' WHERE 't'.'team_id' = 'm'.'team_id' AND 's'.'school_id' = 'm'.'school_id'"; if (!($result = @ mysql_query ($sql, $connection))) { showerror(); } print "<table border=1>"; print "<th>"; $row = @ mysql_fetch_array($result, MYSQL_NUM); foreach($row as $attrib_name) { echo "<td>"; echo "<b>$attrib_name</b>"; echo "</td>"; } print "</th>"; while ($row = @ mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr>"; foreach($row as $attribute) { echo "<td>$attribute</td>"; } echo "</tr>"; } ?> </table> </body> </html>