CG 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>Member List</title>
</head>
<body>
<?php

/**
 * Members -- HW Assignment #3 CPSC-225
 *
 * This php document accesses a MySQL database that contains three tables (members, schools, and teams). Then, using join commands, all the required data is accessed and placed in one table using php
 * 
 *
 * @author Colin Gigl <colin.gigl@trincoll.edu>
 * @version 1.0
 * 
 */

/**
 * Function showerror
 *
 * Should the program throw an error, this function kills the running program and outputs information that is relevant to the error
 *
 */

   function showerror()
   {
      die("Error " . mysql_errno() . " : " . mysql_error());
   }

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

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

   // MySQL command to query all the relevent information from the database
   if (!($result = @ mysql_query ("SELECT name, email, members.school, state, role, team_name FROM members, schools, teams WHERE members.school = schools.school AND members.team_num = teams.team_num", $connection)))
      showerror();

   
   // Prints out all the returned data from MySQL

   print "<table border=1> <tr><th>Name</th><th>E-Mail</th><th>School</th><th>State</th><th>Role</th><th>Team Name</th></tr>";

   while ($row = @ mysql_fetch_array($result, MYSQL_NUM))
   {
	
	print "<tr>";

      foreach ($row as $attribute)
	{
         print "<td> {$attribute} </td> ";
	}

	print "</tr>";

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