survey_seahorse

Software Engineering Project - Fall 2018
Log | Files | Refs | README

query.php (665B)


      1 <?php
      2 include_once '../config.php';
      3 header('Content-Type: application/json');
      4 $question = $_GET['question'];
      5 $sid = $_GET['sid'];
      6 $type = $_GET['type'];
      7 
      8 if ($type == 48) {
      9     $table = 'answer_numeric';
     10 } elseif ($type == 49) {
     11     $table = 'answer_bool';
     12 } else {
     13     header("Location: res/nope.php");
     14     exit();
     15 }
     16 $query = sprintf("SELECT question_number, answer, count(answer) AS num_ans FROM $table WHERE (survey_id=$sid AND question_number=$question) GROUP BY answer ORDER BY answer;");
     17 
     18 $result = $connect->query($query);
     19 
     20 $data = array();
     21 foreach ($result as $row) {
     22     $data[] = $row;
     23 }
     24 
     25 $result->close();
     26 $connect->close();
     27 print json_encode($data);
     28 ?>