Humanitarian Open Source Software Development: Student R MySQL Source Code

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

From Humanitarian-FOSS Project Development Site

<html>
<head>
  <title>Course List</title>
</head>

<body>

<h3> Course List </h3>

<table border =3>
<tr><th>Email</th> <th>Name</th>  <th> Role </th> <th> School </th></tr>
<?php

/**
* Title: Sahana Membership List
* @Author: Student R
* @Version 1.0
*/


/**
* 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());
   }
  
//Connect to localhost database
if(!($connection = mysql_connect("localhost","root","")))
    die("Could not connect");

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

//Select the members database
if(!($members = @ mysql_query("SELECT * FROM members", $connection)))
  showerror();

//for each row print the data into the table
while($row = mysql_fetch_array($members, MYSQL_NUM))
  {
    $email = $row[0];
    $name = $row[1];
    $role = $row[2];
    $school = $row[3];
    $teamid = $row[4];

  if(!($team= @ mysql_query("SELECT teamName FROM teams WHERE id = $teamid", $connection)))
     showerror();
  }
  
  $team_row = @ mysql_fetch_array($teams, MYSQL_NUM);
  $team = $team_row[0];
  
// Query Get the school's state
  if (!($state_result = @ mysql_query ("SELECT state FROM schools WHERE name='{$school}'", $connection)))
        showerror();
  $state_row = @ mysql_fetch_array($state, MYSQL_NUM);
  $state = $state_row[0];
  print "<tr><td>{$name}</td><td>{$email}</td><td>{$school}</td><td>{$state}</td><td>{$role}</td><td>{$team}</td></tr>";
  

?>

</html>
Personal tools