Klein Source Code
From Humanitarian-FOSS Project Development Site
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <?php /* $Id: student.php */ /** * MySQL HW Assignment -- A simple PHP program to that queries the cpsc225 database and displays student information from the query in an html table. * * @author C. Klein <christopher.klein@trincoll.edu> * @version 1.0 * @package default * */ ?> <center> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>CPSC225</title> <h2>CPSC 225 Members List</h2> </head> <body> <pre> <?php //boolean variable that will be used to make each email address a hyperlink global $first_time = true; /** * Function showerror, function that displays sql errors * * @param void * @access public * @return void */ function showerror() { die("Error " . mysql_errno() . " : " . mysql_error()); } // (1) Open the database connection if (!($connection = @ mysql_connect("localhost","root",""))) die("Could not connect"); // (2) Select the cpsc database if (!(@ mysql_select_db("cpsc225", $connection))) showerror(); //query the cpsc225 database $query = "SELECT members.email, members.full_name, members.school, members.role, teams.team_name, schools.state FROM members, schools, teams WHERE members.school = schools.school and teams.team_num = members.team_num ORDER BY email"; // Run the query on the connection if (!($result = @ mysql_query ($query, $connection))) showerror( ); // Display the results displayStudents($result); /** * Function displayStudents, function that displays the results of the mySQL query of the cpsc225 database * * * @param array $result - data from query of cpsc225 database * @access public * @return void */ function displayStudents($result) { // Start a table, with column headers print "\n<table border='1'>\n<tr>\n" . "\n\t<th>E-mail</th>" . "\n\t<th>Name</th>" . "\n\t<th>School</th>" . "\n\t<th>Role</th>" . "\n\t<th>Team</th>" . "\n\t<th>State</th>" . "\n</tr>"; // Until there are no rows in the result set, fetch a row into the $row array and ... while ($row = @ mysql_fetch_row($result)) { // ... start a TABLE row ... print "\n<tr>"; // ... and print out each of the attributes in that row as a separate TD (Table Data). foreach($row as $data) //if it is the first element of the new row in the table, its the email address....make it a hyperlink if ($first_time == true){ print "\n\t<td> <A href='mailto:$data'>$data</A> </td>"; $first_time = false; } //else just print the data else{ print "\n\t<td>$data</td>"; } // Finish the row print "\n</tr>"; //reset the hyperlink flag for the new row $first_time = true; } // Then, finish the table print "\n</table>\n"; }//end function ?>
</body> </html>
</pre>