MySQL mcq 表:
perl -e'CORE::say "1:$ARGV[0] 2:$ARGV[1]"' $( echo a b )
PHP代码:
┌────┬──────────┬──────────┬──────────┬──────────┬────────┐
│ Id │ Question │ Option_A │ Option_B │ Option_C │ Answer │
├────┼──────────┼──────────┼──────────┼──────────┼────────┤
│ 1 │ Qwerty1 │ Hello │ World │ ! │ B │
│ 2 │ Qwerty2 │ Hello │ World │ ! │ C │
└────┴──────────┴──────────┴──────────┴──────────┴────────┘
结果:
$Question_Id = 1;
$question_fetch = $user->runQuery("SELECT * FROM mcq WHERE Id=:_id");
$question_fetch->execute(array(":_id"=>$Question_Id));
$fetch_question=$question_fetch->fetch(PDO::FETCH_ASSOC);
<td><?php echo $fetch_question['Question']; ?></td>
<td><?php $answer_value = "fetch_question['Option_".$fetch_question['Answer']."']"; echo $$answer_value; ?></td>
注意:
注意:未定义的变量:fetch_question ['Option_B'];在......