Created
October 16, 2008 16:44
-
-
Save pol/17192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<title>Results of Survey</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
</head> | |
<body> | |
<h1 align="center">Results of Survey</h1> | |
<center> | |
<?php | |
function dbp($instring){ | |
global $testing; | |
if ($testing){ | |
print "dbp>".$instring."<br /> \n"; # The \n makes the source code more readable | |
} | |
} | |
# Main program begins here | |
$testing=1; | |
# we have three courses to store data for | |
# this is just an array to hold the POSTED data from the form. | |
$courses = array( | |
'1' => array ('ireply' => 0, 'mreply' => 0), | |
'2' => array ('ireply' => 0, 'mreply' => 0), | |
'3' => array ('ireply' => 0, 'mreply' => 0) | |
); | |
# First: Get the data from the form, restrict to the courses, they are in ireply# and mreply# values | |
foreach($courses as $key => $val){ | |
$courses[$key]['ireply'] = $_POST['ireply'.$key]; | |
$courses[$key]['mreply'] = $_POST['mreply'.$key]; | |
} | |
dbp(print_r($courses)); | |
# Connect to the db | |
$connection = mysql_connect("localhost","root",""); | |
mysql_select_db("bithlo2", $connection); | |
# update the database for each of the courses, increment the score value for each one | |
foreach($courses as $key => $val){ | |
$iscore = 'score'.$val['ireply']; #just for simplification, which score is it | |
$mscore = 'score'.$val['mreply']; | |
#preset the values (assume there aren't any in the database, they will be overwritten if they are.) | |
$courses[$key]['icount'] = 1; | |
$courses[$key]['mcount'] = 1; | |
#select the course rows (both instructor and materials) | |
$query = "SELECT * from bithlosurvey2 where Course = '$key'"; | |
$result = mysql_query($query, $connection); | |
while($course_row = mysql_fetch_array($result)){ | |
if($course_row['Question'] == 'instructor'){ | |
$courses[$key]['icount'] = $course_row[$iscore] + 1; | |
$courses[$key]['ipid'] = $course_row['pid']; | |
}else{ | |
$courses[$key]['mcount'] = $course_row[$mscore] + 1; | |
$courses[$key]['mpid'] = $course_row['pid']; | |
} | |
dbp("Existing Database Record: ". print_r($course_row)); | |
} | |
#for the instructor, update the database. | |
#now, either insert new rows or update existing ones, depending | |
if(isset($courses[$key]['ipid'])){ | |
$query = "UPDATE bithlosurvey2 SET ${iscore} = ".$courses[$key]['icount']." where pid = ".$courses[$key]['ipid']; | |
}else{ | |
$query = "INSERT INTO bithlosurvey2 SET ${iscore} = ".$courses[$key]['icount'].", Course = '${key}', Question = 'instructor'"; | |
} | |
dbp($query); | |
#run the query | |
$result = mysql_query($query, $connection); | |
#for the materials, update the database. | |
#now, either insert new rows or update existing ones, depending | |
if(isset($courses[$key]['mpid'])){ | |
$query = "UPDATE bithlosurvey2 SET ${mscore} = ".$courses[$key]['mcount']." where pid = ". $courses[$key]['mpid']; | |
}else{ | |
$query = "INSERT INTO bithlosurvey2 SET ${mscore} = ".$courses[$key]['mcount'].", Course = '${key}', Question = 'materials'"; | |
} | |
dbp($query); | |
#run the query | |
$result = mysql_query($query, $connection); | |
} | |
# This portion displays the results | |
$myquery= "SELECT * FROM bithlosurvey2"; | |
$result = mysql_query ($myquery, $connection); | |
dbp("queried bithlo2 table. Query=".$myquery); | |
print "<table border=1 cellpadding=2>"; | |
print "<tr><th>Winery</th><th>Product</th><th>Excellent</th><th>Good</th><th>Fair</th><th>Poor</th></tr>"; | |
while ($row = mysql_fetch_array($result)) | |
{ | |
// (4) Print out each element in $row, that is, print the values of | |
// the attributes | |
print "<tr>"; | |
print "<td>".$row['Instructor']."</td>"; | |
print "<td>".$row['Materials']."</td>"; | |
print "<td align=center>".$row['score1']."</td>"; | |
print "<td align=center>".$row['score2']."</td>"; | |
print "<td align=center>".$row['score3']."</td>"; | |
print "<td align=center>".$row['score4']."</td>"; | |
print "<td align=center>".$row['score5']."</td>"; | |
print "</tr> \n"; # the \n makes the source code more readable | |
} | |
print "</table>"; | |
print '<p> | |
<form action="bithlocap2.html" method="POST"> | |
<input type="submit" value="CONTINUE GATHERING DATA"> | |
</form> | |
<form action="surveyzero.php" method="POST"> | |
<input type="submit" value="CLEAR THE DATABASE"> | |
</form> | |
</p> | |
'; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment