From 5676c39b544003474a21af8454ac1b8abb2b43b8 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 22 Jan 2010 17:36:45 +0000 Subject: [PATCH] Properly load ALL questions for a user, even if they don't have answer records for some of them --- questions.inc.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/questions.inc.php b/questions.inc.php index 09ca213..dc1bfc1 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -26,16 +26,15 @@ function questions_load_answers($section, $users_id) { - $q = mysql_query('SELECT question_answers.*, questions.* '. - 'FROM question_answers '. - 'LEFT JOIN questions ON questions.id=question_answers.questions_id '. - "WHERE users_id='$users_id' ". - " AND questions.section='$section' ". - 'ORDER BY questions.ord ASC'); - - $ans = array(); - while($r=mysql_fetch_object($q)) { - $ans[$r->questions_id] = $r->answer; + global $config; + $yearq=mysql_query("SELECT `year` FROM users WHERE id='$users_id'"); + $yearr=mysql_fetch_object($yearq); + $ans=array(); + $qs=questions_load_questions($section,$yearr->year); + foreach($qs AS $id=>$question) { + $q=mysql_query("SELECT * FROM question_answers WHERE users_id='$users_id' AND questions_id='$id'"); + $r=mysql_fetch_object($q); + $ans[$id]=$r->answer; } return $ans; }