Skip to content

Instantly share code, notes, and snippets.

Created November 21, 2012 23:53
Show Gist options
  • Save anonymous/4128615 to your computer and use it in GitHub Desktop.
Save anonymous/4128615 to your computer and use it in GitHub Desktop.
WIP: Survey question summary, based on older Countries MVC model.
<?php
require_once 'models/question.php';
require_once ("dbconfig.php");
class Model {
public function summary(){
$summ = array();
for ($i = 0; $i < 49; $i++)
{
$summ[$i] = 0;
}
$dbc = new DBConfig();
$db = new PDO($dbc -> dsn, $dbc -> user, $dbc -> pass);
$sql = "select * from it609data order by firstname";
$rows = $db -> query($sql);
foreach ($rows as $row) {
$q1 = $row['cheeseQ1']; //$sum[0-4]
$q2 = $row['cheeseQ2']; //$sum[5-9]
$q3 = $row['cheeseQ3']; //$sum[10-14]
$q4 = $row['cheeseQ4'];//$sum[15-19]
$q5 = $row['cheeseQ5'];//$sum[20-24]
$q6 = $row['cheeseQ6'];//$sum[25-29]
$q7 = $row['cheeseQ7'];//$sum[30-34]
$q8 = $row['cheeseQ8'];//$sum[35-39]
$check1a = $row['cheeseCheck1a'];
$check1b = $row['cheeseCheck1b'];
$check1c = $row['cheeseCheck1c'];
$check1d = $row['cheeseCheck1d'];
$check2a = $row['cheeseCheck2a'];
$check2b = $row['cheeseCheck2b'];
$check2c = $row['cheeseCheck2c'];
$check2d = $row['cheeseCheck2d'];
$q1sum = $q1 -1;
$summ[$q1sum] += 1;
$q2sum = $q2 +5 -1;
$summ[$q2sum] += 1;
$q3sum = $q3 +10 -1;
$summ[$q3sum] += 1;
$q4sum = $q4 +15 -1;
$summ[$q4sum] += 1;
$q5sum = $q5 +20 -1;
$summ[$q5sum] += 1;
$q6sum = $q6 +25 -1;
$summ[$q6sum] += 1;
$q7sum = $q7 +30 -1;
$summ[$q7sum] += 1;
$q8sum = $q8 +35 -1;
$summ[$q7sum] += 1;
if($check1a == 1)
{
$summ[40] += 1;
}
if($check1b == 1)
{
$summ[41] += 1;
}
if($check1c == 1)
{
$summ[42] += 1;
}
if($check1d == 1)
{
$summ[43] += 1;
}
if($check2a == 1)
{
$summ[44] += 1;
}
if($check2b == 1)
{
$summ[45] += 1;
}
if($check2c == 1)
{
$summ[46] += 1;
}
if($check2d == 1)
{
$summ[47] += 1;
}
$summ[48] += 1;
}
$summResults = array();
$radiooptions = array();
$totalRecords = $summ[48];
for ($i = 0;$i<8;$i++)
{
$radioparts = array();
for ($i = 0;$i < 5; $i++)
{
$questionName = "Question" + ($i + 1);
$radioparts[$i] = new Question($questionName, $summ[$i]);
}
usort($radioparts, array("Question", "cmp_obj"));
$radiooptions[$i] = $radioparts[4];
}
$db=null;
return $countries;
/*
return array(
"1"=>new Country("1","New Zealand",268680,4383600,16.32,"newzeala.gif"),
"2"=>new Country("2","China",9596960,1339190000,139.54,"china.gif"),
"3"=>new Country("3","Australia",7686850,22421417,2.92,"australi.gif"),
);
*/
}
public function getCountry($cid){
$allCountries = $this->getCountries();
return $allCountries[$cid];
}
public function updateCountry($country){
$countries = array();
$dbc = new DBConfig();
$db = new PDO($dbc -> dsn, $dbc -> user, $dbc -> pass);
$sql = "update countries set name=?,population=?,area=?,popdensity=? where cid=?";
$st = $db->prepare($sql);
$st->bindParam(1,$country->name);
$st->bindParam(2,$country->population);
$st->bindParam(3,$country->area);
$st->bindParam(4,$country->popdensity);
$st->bindParam(5,$country->cid);
$st->execute();
$db=null;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment