Humanitarian Open Source Software Development: Students N, O 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 CLASS LIST by Team Average Joe</title>
</head>
<body>
<?php
	/**
	 * Prints classmates information based on information in a MYSQL databse. 
	 * We used Joint Queries to display the data from mutliple tables.
	 * @author Student N, Student O
         * @version 1.0
	 *
	 */
	
	/**
	 * ShowError is a default error function written in case errors occur
	 * while connecting to the databse.
         * @access public
         * @return void
	 */
	   function showerror()
	   {
	      die("Error " . mysql_errno() . " : " . mysql_error());
	   }

  
   /**
    * Open the databse connection. If there is an error instead of printing out possible information
    * that could expose your username and password, the default error is overwritten, instead dying
    * saying only "could not connect"
    */
   if (!($connection = @ mysql_connect("localhost","root","")))//Open the database connection
      die("Could not connect");

   if (!(@ mysql_select_db("cpsc225", $connection)))// (Selects the cpsc225 databse
      showerror();

	/**
	 * Join queries are used match information from the three tables, members, schools, and teams.
	 * The information is then tied together using "WHERE" statements. Finally the data is organized b
	 * team for easier viewing. If mysql query fails showerror msg is shown.
	 */
   if (!($result = @ mysql_query (
   		" SELECT DISTINCT members.name,members.email,members.school,
   						   schools.schools_state,members.role,teams.team_name
	       FROM members,teams,schools
	       WHERE members.school=schools.schools_name AND
	       		 members.team_num=teams.team_key
	       ORDER BY teams.team_key", //order by team name
   		
   		$connection)))
      showerror();
		/**
		 * HTML to create, and label the table.
		 */
   		echo "<center>";
		echo "<table border='1'>";		
		echo "<tr>";	
		echo "<thead>";
	        echo "<TD>
		     <CENTER><B>Member</CENTER></B></TD>
	    	 <TD><CENTER><B>Email</CENTER></B></TD>
	    	 <TD><CENTER><B>School</CENTER></B></TD>
	   		 <TD><CENTER><B>State</CENTER></B></TD>
	         <TD><CENTER><B>Role</CENTER></B></TD>
	    	 <TD><CENTER><B>Team Name</CENTER>
	     	 </B></TD></TR></THEAD>";
	    
   while ($row = @ mysql_fetch_array($result, MYSQL_NUM))
   {
      foreach ($row as $attribute) //each sql value is put into an HTML table. 
      {
      	echo "<td>";
        print "{$attribute} ";
        echo "</td>";
      }
	  echo "<tr>";
      print "\n";
   }


?>
</body>
</html>
Personal tools