如何通过单选名称按钮将答案ID插入数据库中?因为当我尝试插入答案ID时,书面代码只为第一个if语句插入了答案ID
NotificationManagerCompat
这是插入代码
<div class="coursebox">
<?php
echo '<div class="question-box" style="border-bottom: 0;"><h2>';
str('assess_exam');
echo'</h2></div>';
if($questions = $wpdb->get_results("SELECT * FROM evaluation_test WHERE year = 'half_year'")){
echo '<form method="POST">';
echo '<input type="hidden" value="'. sizeof($questions) .'" name="num_of_ques" />';
$q_counter = 1;
foreach ($questions as $q) {
echo '<div class="question-box">';
$ques = $l == 1 ? $q->q_en : $q->q_ar;
echo '<p>'. $ques .'</p>';
echo '<input type="hidden" value="'. $q->id .'" name="q_id[]" />';
if($answers = $wpdb->get_results("SELECT * FROM evaluation_answers WHERE q_id = $q->id")){
foreach ($answers as $ans) {
$a = $l == 1 ? $ans->ans_en : $ans->ans_ar;
echo '<label><input type="radio" value="'. $ans->id .'" name="q_'.$q_counter.'_ans" required checked />'. $a .'</label>';
}
}
echo '</div>';
$q_counter++;
}
echo '
</form>
';
}
echo '<div class="question-box" style="border-bottom: 0;"><h2>';
str('assess_exam');
echo'</h2></div>';
if($questions = $wpdb->get_results("SELECT * FROM evaluation_test WHERE year ='one_year'")){
echo '<form method="POST">';
echo '<input type="hidden" value="'. sizeof($questions) .'" name="num_of_ques" />';
$q_counter = 1;
foreach ($questions as $q) {
echo '<div class="question-box">';
$ques = $l == 1 ? $q->q_en : $q->q_ar;
echo '<p>'. $ques .'</p>';
echo '<input type="hidden" value="'. $q->id .'" name="q_id[]" />';
if($answers = $wpdb->get_results("SELECT * FROM evaluation_answers WHERE q_id = $q->id")){
foreach ($answers as $ans) {
$a = $l == 1 ? $ans->ans_en : $ans->ans_ar;
echo '<label><input type="radio" value="'. $ans->id .'" name="q_'.$q_counter.'_ans" required checked />'. $a .'</label>';
}
}
echo '</div>';
$q_counter++;
}
echo '
</form>
';
}
if(current_user_can('teacher')){
echo '<button type="submit" name="save_report">'; echo $get_strings->save_report[$l]; echo'</button>';
}
?>
</div>
我需要将答案ID与单选按钮的名称插入数据库表中,能否请我指导谁进行操作。 非常感谢。