MoveNext(); array_push($qidc_content, $row); } db_close($result); unset($sql); } } else if ($tid == 1){ foreach($tid_content as $content){ if ($content == 'Y'){ $content = 'Yes'; } else { $content = 'No'; } array_push($qidr_content, $content); } } else{ $sql = "SELECT content FROM ".$GLOBALS['ESPCONFIG']['question_choice_table']." WHERE question_id=${qidr} ORDER BY id"; if ($result = execute_sql($sql)){ while (list($row) = fetch_row($result)){ $result->MoveNext(); array_push($qidr_content, $row); } db_close($result); unset($sql); } } $tid_count++; } reset($tids); $tidcounter = 0; // Now to build the tabulation arrays that hold response counts. foreach ($qids as $qid){ switch ($tids[$tidcounter]){ case 1: $from_table = $GLOBALS['ESPCONFIG']['response_bool_table']; $order = 'id'; $table = $GLOBALS['ESPCONFIG']['response_bool_table']; array_push($tbl, $table); break; case 4: case 6: $from_table = $GLOBALS['ESPCONFIG']['question_choice_table']; $order = 'id'; $table = $GLOBALS['ESPCONFIG']['response_single_table']; array_push($tbl, $table); break; case 5: $from_table = $GLOBALS['ESPCONFIG']['question_choice_table']; $order = 'id'; $table = $GLOBALS['ESPCONFIG']['response_multiple_table']; array_push($tbl, $table); break; } if ($tids[$tidcounter] == 1){ if ($tidcounter == 0){ foreach($tid_content as $content){ array_push($cids_col, $content); } } else{ foreach($tid_content as $content){ array_push($cids_row, $content); } } } else { $sql = "SELECT id FROM ".$from_table." WHERE question_id = $qids[$count] ORDER BY $order"; $result = execute_sql($sql); while ($cid = fetch_row($result)){ $result->MoveNext(); if ($count == 0){ array_push($cids_col, $cid[0]); } else{ array_push($cids_row, $cid[0]); } } db_close($result); } $count++; $tidcounter++; } $num = 0; $cids_col_count = sizeof($cids_col); $cids_row_count = sizeof($cids_row); foreach ($cids_row as $yy){ $total_row = 0; foreach ($cids_col as $xx){ $sql1 = "SELECT count(*) FROM ".$tbl[0]." r1, ".$tbl[1]." r2 WHERE (r1.question_id = ${qids[0]} AND r1.choice_id = '${xx}') AND (r2.question_id = ${qids[1]} AND r2.choice_id = '${yy}') AND r1.response_id = r2.response_id"; $result1 = execute_sql($sql1); while ($counts = fetch_row($result1)){ $result1->MoveNext(); $total_row += intval($counts[0]); array_push($col_counts, $counts[0]); } } array_push($row_totals,$total_row); } // let's build the cross-tabulation results table ?>
".$qn_content[1]."\""); ?> ".$qn_content[0]."\""); ?>
| "); echo (" | ");
echo (" ".$content." | \n");
}
unset($content);
?>
Totals |
"); echo ("".$qidr_content[$q++].": | \n"); } if ($counter == $cids_col_count+1){ echo ("");
echo (" ".$row_totals[$rt++]." | \n");
echo ("\n");
echo ("
| "); echo ("".$qidr_content[$q++].": | \n"); echo ("");
echo (" ".$tt." | \n");
$counter = 1;
}
else {
echo ("");
echo (" ".$tt." | \n");
}
}
echo ("");
echo (" ".$row_totals[$rt++]." | \n");
echo ("
| \n");
echo (" TOTALS | \n");
$grand_total = 0;
for ($f = 0; $f < $cids_col_count; $f++){
for ($g = 0; $g < $cids_row_count; $g++){
if ($g == 0){
$subtotal = $f;
$total = intval($col_counts[$f]);
}
else {
$subtotal += $cids_col_count;
$total += intval($col_counts[$subtotal]);
}
}
echo ("");
echo (" ".$total." | \n");
$grand_total += $total;
unset($total);
}
echo ("");
echo (" ".$grand_total." | \n");
echo ("
Go back to Cross Analysis/Tabulation