diff --git a/admin/statistics.php b/admin/statistics.php
index 0a1aa9f5d62..003d03b0eb7 100644
--- a/admin/statistics.php
+++ b/admin/statistics.php
@@ -87,21 +87,21 @@
}
//echo $flt[2]; //debugging line
if ($counter == 5) {echo "\t\t\t\t\n\t\t\t\t
";}
+ $myfield = "{$sid}X{$flt[1]}X{$flt[0]}";
if ($flt[2] != "A" && $flt[2] != "B" && $flt[2] != "C") //Have to make an exception for these types!
{
echo "\t\t\t\t";
echo "$setfont$flt[3] "; //Heading (Question No)
- echo " ";
- echo " ";
+ echo " ";
echo " \n";
echo "\t\t\t\t\n";
}
- $myfield = "{$sid}X{$flt[1]}X{$flt[0]}";
- if ($flt[2] == "M" || $flt[2] == "P") {$myfield = "M$myfield";}
echo "\t\t\t\t\t\n";
switch ($flt[2])
{
@@ -226,33 +226,9 @@
echo "\t\n";
echo "\n";
-/// MUCKING AROUND ----
-//phpinfo();
-
-//echo count($_POST) . " elements ";
-//foreach ($_POST as $post)
-// {
-// if (is_array($post))
-// {
-// foreach ($post as $pst)
-// {
-// echo "$pst \n";
-// }
-// }
-// else
-// {
-// echo "$post \n";
-// }
-// echo " \n";
-// }
-
-//for($i=0;$i \n\n";
- echo "\t$setfontResults: \n";
+ echo "\t$setfontResults \n";
echo "\t$setfont";
echo "Your query returns $results record(s)! \n\t\t";
echo "There are $total records in your survey. This query represents ";
@@ -333,31 +309,88 @@
if ($_POST['summary'])
{
- //1. Get distinct results for field
- $query = "SELECT DISTINCT {$_POST['summary']} FROM survey_$sid ORDER BY {$_POST['summary']}";
- $result=mysql_query($query) or die("Couldn't get distinct results $query ".mysql_error());
- while ($row=mysql_fetch_row($result))
+ // 1. Get answers for question
+ if (substr($_POST['summary'], 0, 1) == "M") //MULTIPLE OPTION, THEREFORE MULTIPLE FIELDS. HOW THE HELL DO WE DO THIS ONE?
{
- $fvalues[]=$row[0];
+
+ list($qsid, $qgid, $qqid) = explode("X", substr($_POST['summary'], 1, strlen($_POST['summary'])));
+ $nquery = "SELECT title, type, question FROM questions WHERE qid='$qqid'";
+ $nresult = mysql_query($nquery) or die ("Couldn't get question $nquery ".mysql_error());
+ while ($nrow=mysql_fetch_row($nresult)) {$qtitle=$nrow[0]; $qtype=$nrow[1]; $qquestion=strip_tags($nrow[2]);}
+
+ //1. Get list of answers
+ $query="SELECT code, answer FROM answers WHERE qid='$qqid'";
+ $result=mysql_query($query) or die("Couldn't get list of answers for multitype $query ".mysql_error());
+ while ($row=mysql_fetch_row($result))
+ {
+ $mfield=substr($_POST['summary'], 1, strlen($_POST['summary']))."$row[0]";
+ $alist[]=array("$row[0]", "$row[1]", $mfield);
+ }
+ //foreach ($mfields as $mf) {echo "$mf";} //debug line
+ //2.
+ }
+ else // NICE SIMPLE SINGLE OPTION ANSWERS
+ {
+ list($qsid, $qgid, $qqid) = explode("X", $_POST['summary']);
+ $nquery = "SELECT title, type, question FROM questions WHERE qid='$qqid'";
+ $nresult = mysql_query($nquery) or die ("Couldn't get question $nquery ".mysql_error());
+ while ($nrow=mysql_fetch_row($nresult)) {$qtitle=$nrow[0]; $qtype=$nrow[1]; $qquestion=strip_tags($nrow[2]);}
+ $alist[]=array("", "No Answer");
+ switch($qtype)
+ {
+ case "G": //Gender
+ $alist[]=array("F", "Female");
+ $alist[]=array("M", "Male");
+ break;
+ case "Y": //Yes\No
+ $alist[]=array("Y", "Yes");
+ $alist[]=array("N", "No");
+ break;
+ case "5": //5 Point
+ for ($i=1; $i<=5; $i++)
+ {
+ $alist[]=array("$i", "$i");
+ }
+ default:
+ $qquery = "SELECT code, answer FROM answers WHERE qid='$qqid' ORDER BY code";
+ $qresult = mysql_query($qquery) or die ("Couldn't get answers list $qquery ".mysql_error());
+ while ($qrow=mysql_fetch_row($qresult))
+ {
+ $alist[]=array("$qrow[0]", "$qrow[1]");
+ }
+ }
}
+
+ //foreach ($alist as $al) {echo "$al[0] - $al[1] ";} //debugging line
//foreach ($fvalues as $fv) {echo "$fv | ";} //debugging line
+
+ //2. Display results
echo " \n\n";
- echo "\t$setfontField Summary for {$_POST['summary']}: \n";
- echo "\t\n\t\t$setfontAnswer \n";
+ echo "\t $setfontField Summary for $qtitle: ";
+ echo " \n";
+ echo "\t$setfont$qquestion \n";
+ echo "\t\n\t\t$setfontAnswer \n";
echo "\t\t$setfontCount \n";
echo "\t\t$setfontPercentage \n";
echo "\t \n";
- foreach ($fvalues as $fv)
+ foreach ($alist as $al)
{
- $query = "SELECT count({$_POST['summary']}) FROM survey_$sid WHERE {$_POST['summary']} = '$fv'";
+ if ($al[2]) //picks out alist that come from the multiple list above
+ {
+ $query = "SELECT count($al[2]) FROM survey_$sid WHERE $al[2] = 'Y'";
+ }
+ else
+ {
+ $query = "SELECT count({$_POST['summary']}) FROM survey_$sid WHERE {$_POST['summary']} = '$al[0]'";
+ }
if ($sql) {$query .= " AND $sql";}
$result=mysql_query($query) or die ("Couldn't do count of values $query ".mysql_error());
while ($row=mysql_fetch_row($result))
{
- if ($fv == "") {$fname="No Answer";} else {$fname=$fv;}
+ if ($al[0] == "") {$fname="No Answer";} else {$fname="$al[1] ($al[0])";}
echo "\t\n\t\t$setfont$fname:\n\t\t \n";
echo "\t\t$setfont$row[0]";
- $vp=sprintf("%02d", ($row[0]/$results)*100);
+ if ($results > 0) {$vp=sprintf("%02d", ($row[0]/$results)*100);} else {$vp="No Records";}
echo "\t\t $setfont$vp%";
echo "\t\t \n";
}