Humanitarian Open Source Software Development: Student E MySQL Source Code

[article] [edit page] [discussion] [history]

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>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>CPSC 225: Member List</title>
</head>
<body>
<?php
/**
* Sahana Memberlist
*
* MySQL exercise designed to show mastery of the basics of the SQL database language.
* Displays the list of the members of the Sahana project by joining the members,schoools and teams tables.
*
* @author Student E
* @version 1.0
*/
?>
<?php
	/**
	* Function showerror, displays a sql error.
	*
	* This function simply takes any sql error that may have occured 
	* and displayes an error on the php page calling the query.
	* 
	* @access public
	* @return void
	*/
   function showerror()
   {
      die("Error " . mysql_errno() . " : " . mysql_error());
   }

   if (!($connection = @ mysql_connect("localhost","root","")))
      die("Could not connect");

   if (!(@ mysql_select_db("cpsc225", $connection)))
      showerror();

   if (!($result = @ mysql_query ("SELECT fname,email,school,schools.state,role,teams.teamname FROM members,schools,teams 
						WHERE members.teamnum = teams.teamnum AND members.school = schools.sname 
						 GROUP BY email", $connection)))
      showerror();

	printMemberList($result)
?>
<?php
	/**
	* Function printMemberList, prints the member list as a table.
	*
	* This function takes a previously called result from the database and 
	* prints out a table w/ the appropriate header information. cycles through the
	* result table and prints out the differnt values for each member.
	*
	* @param array $table table of return results from a sql query.
	* @access public
	* @return void
	*/
	function printMemberList($table) {
	echo "<table border = 1><tr>";
	echo "<th>Member<th>Email<th>School<th>State<th>Role<th>Team Name\n";
	   while ($row = @ mysql_fetch_array($table, MYSQL_NUM))
	   {	
		echo "<tr>";
	      foreach ($row as $attribute)
	         echo "<td> {$attribute}";
	
	      // Print a carriage return to neaten the output
		echo "\n";
	   }
	}
?>
</body>
</html>
Personal tools