【发布时间】:2016-04-06 10:42:28
【问题描述】:
for ($i=0; $i<$total_questions_for_exam; $i++) {
$question_id= $question_and_answers[$i]['question_id'];
$numberofanswersperquestion = count_answers_belongToOne_questionNew($question_id);
//die(var_dump($question_id));
$student_answer_per_question = retrieve_student_result ($_SESSION['user_id'], $_GET['quiz_id'], $question_id);
echo ' <table class="table table-bordered table-condensed table-datatable table-hover">
<tbody>
<tr>
<td style="text-align: left;" width="100%"><strong>Question '. ($i+1) .'</strong></td>
</tr>
<tr>
<td style="text-align: left;" width="100%">' . $question_and_answers[$i]['question_name'] .'</td>
</tr>
<tr>
<td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is</strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
</tr>
<tr>
<td style="height: 5px;" width="100%"> </td>
</tr>
<tr>
<td style="height: 5px;" width="100%"> </td>
</tr>
</tbody>
</table>';
}
大家好,我有这个 for 循环,我想做的是,只打印这个
<tr>
<td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is</strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
</tr>
基于 if 语句。但是如何将 if 语句放在 echo 中?
我已经尝试过这种方式,通过
' . if() {} . '
但我无法让它以这种方式工作。
这就是我在 if 语句中想要的
if($student_answer_per_question === '' || '') {
<tr>
<td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is</strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
</tr>
}
我希望我已经详细解释了这个问题,感谢你们的帮助。谢谢
【问题讨论】:
-
你可以拆分你的 echo 语句
-
if($student_answer_per_question === '' || '') {''will always be falsy -
if 语句现在工作正常,但 else 语句由于某种原因没有被调用
标签: php html if-statement echo