Properly load ALL questions for a user, even if they don't have answer records for some of them

This commit is contained in:
james 2010-01-22 17:36:45 +00:00
parent 522ea8206d
commit 5676c39b54

View File

@ -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;
}