Example Survey

\n"; echo "Survey
ChoiceFrequency\n"; echo "A$r[0]\n"; echo "B$r[1]\n"; echo "C$r[2]\n"; echo "D$r[3]\n"; echo "TOTAL$total\n"; echo "\n"; } // Set this to a writable dir accessed by HTML $survey_www_dir = "~zito/php/temp"; // Set this to the Unix equivalent of the above $survey_real_dir = "/user/gruppo_1/zito/WWW/php/temp"; // Set this to the name of the survey $survey_name = "example"; // database name $dbm = $survey_real_dir."/".$survey_name; if ($submit) { /* If the form was submitted, record result in a dbm file */ if ($survey) { if (!fileinode("$dbm.lck")) { $dbmid=dbmopen($dbm,"n"); // file does not exist } else { $dbmid=dbmopen($dbm,"w"); } dbminsert($dbmid,date("U"),$survey." ".$REMOTE_HOST); dbmclose($dbmid); // debug code: // echo "DEBUG: dbminsert($dbmid,",date("U"), // ",$survey$REMOTE_HOST
"; } ?>

Survey Response

Thank you for submitting the survey

[Survey Question]

[See Results]
This is an example survey which can be used as a template for a more complete survey script. It is completely written in the PHP Script language.

What do you think of the language PHP for programming interactive web applications?

A. It is poor.
B. It is good but not great.
C. It is a great language -- one of the best.
D. What is it?
[See Results]
"; } else { echo "

Survey Results

\n"; // If there are results in the dbm file, display them graphically $dbmid=dbmopen($dbm,"r"); $key = dbmfirstkey($dbmid); $r[0] = 0; $r[1] = 0; $r[2] = 0; $r[3] = 0; while ($key) { $res = dbmfetch($dbmid,$key); $a=strtok($res," "); if ($a>="a" && $a<="d") { $r[ord($a)-ord("a")]++; } $key=dbmnextkey($dbmid,$key); } dbmclose($dbmid); $xm = 4 * 32; // find maximum y $total=$r[0]; $ym=$r[0]; for ($i=1;$i<4;$i++) { $total+=$r[$i]; if ($r[$i]>$ym) { $ym=$r[$i]; } } /// $ym = max($r); // this doesn't work printresults(); } echo "
[Survey Question]
\n"; } ?>