You are here

function multichoice_store_answer in Quiz 5.2

Same name and namespace in other branches
  1. 6.6 question_types/multichoice/multichoice.module \multichoice_store_answer()
  2. 6.2 multichoice.module \multichoice_store_answer()
  3. 6.3 question_types/multichoice/multichoice.module \multichoice_store_answer()
  4. 6.5 question_types/multichoice/multichoice.module \multichoice_store_answer()

Store one response to a multichoice question.

Parameters

$nid: Question node id.

$vid: Question node revision id.

$rid: Result id.

$answer_id: The answer id.

1 call to multichoice_store_answer()
multichoice_evaluate_question in ./multichoice.module
Evaluate whether a question is correct.

File

./multichoice.module, line 623
Multiple choice question type for the Quiz module.

Code

function multichoice_store_answer($nid, $vid, $rid, $answer_id, $numanswers) {
  $result = db_query("SELECT result_id FROM {quiz_multichoice_user_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d", $nid, $vid, $rid);
  if (db_num_rows($result) == $numanswers) {
    db_query("UPDATE {quiz_multichoice_user_answers} " . "SET answer_id = %d " . "WHERE question_nid = %d AND question_vid = %d AND result_id = %d", $answer_id, $nid, $vid, $rid);
  }
  else {
    db_query("INSERT INTO {quiz_multichoice_user_answers} " . "(question_nid, question_vid, result_id, answer_id) " . "VALUES (%d, %d, %d, %d)", $nid, $vid, $rid, $answer_id);
  }
}