Advertisement
nathan15

get_question.php

Nov 19th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. include('../config.php');
  3. $test = mysql_real_escape_string($_GET['test']);
  4.  
  5. $question = mysql_query("SELECT *, q.id qid, q.question question_text
  6.                         FROM questions q, user_answers ua
  7.                         WHERE q.id != ua.question_id
  8.                           AND ua.test_id = $test
  9.                           AND ua.user_id = $_SESSION[userid]
  10.                         ORDER BY rand()
  11.                         LIMIT 1");
  12.  
  13. $q = mysql_fetch_assoc($question);
  14.  
  15. $answers = mysql_query("SELECT * FROM answers WHERE question_id = $q[qid] ORDER BY rand()");
  16. $num = 1;
  17. $letters = array('','a','b','c','d','e','f','g','h');
  18. $answersRadios = '';
  19. while($row = mysql_fetch_assoc($answers)) {
  20.     $letter = strtoupper($letters[$num]);
  21.     $answersRadios .= '<div class="answer-line"><input type="radio" class="questionRadio" name="questionRadio" id="question-radio-'.$letter.'" value="'.$row['id'].'" /> <label class="radio-label" for="question-radio-'.$letter.'">'."<strong>$letter.</strong> $row[answer]".'</label> </div>';
  22.     $num++;
  23. }
  24. if(mysql_num_rows($answers)==0) {
  25.     $answersRadios = '<em>Sorry, but there aren\'t any answers for this question in the database.</em>';
  26. }
  27. $i = array(
  28.     'id'=>$q['qid'],
  29.     'qText'=>$q['question_text'],
  30.     'directions'=>$q['instructions'],
  31.     'answers'=>$answersRadios
  32. );
  33. echo json_encode($i);
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement