我的for循环为什么只能循环一次···

wagu08090 2010-11-30 10:46:54
我写的一个在线考试系统 对多选题答案做判断 用的for循环来循环得到的结果 题目被选择的选项个数跟正确答案个数不一样 然后提示本题错误 继续循环下一题 但是 如果被选择的选项个数跟正确答案个数一样的话 不管最后是正确还是错误 都不能在继续循环下一题了 下边是我的代码 大家帮忙看看 哪儿出问题了 先谢谢了···

if($_POST['ac'] == 'duoxuan'){
$num = $db->GETALL("select count(*) as num from tol_obj_question where obj_type = 2");
$num = $num['0']['num'];
for($i=1;$i<=$num;$i++){
$string = "item".$i;
if(!isset($_POST[$string])){
echo "<script>alert('您还有没有做完的题目!');history.back();</script>";
}
}
for($i=1;$i<=$num;$i++){
echo $i;
$string = "item".$i;
$result = $_POST[$string];
$id = $_POST['question_id'];
$num = count($result); //被选上的选项的数目
$right_num = $db->getall("select count(*) as num from tol_obj_item where item_is_right = 1 and obj_question_id = $id");
$right_num = $right_num['0']['num']; //数据库中正确的选项的数目
if($num == $right_num){
$j = 0;
foreach($result as $v){
if($v == 1){
$j = $j+1;
}
}
if($j == $right_num){
echo '题目'.$i.'、right';
} else {
echo '题目'.$i.'、error';
}
}else{
echo '题目'.$i.'error';
}
echo "正确答案是:";
}
}
...全文
186 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wagu08090 2010-12-01
  • 打赏
  • 举报
回复
谢谢这位大哥 问题解决了···
amani11 2010-11-30
  • 打赏
  • 举报
回复

for($i=1;$i<=$num;$i++){
echo $i;
$string = "item".$i;
$result = $_POST[$string];
$id = $_POST['question_id'];
$num = count($result); //被选上的选项的数目

//$num重新赋值,count 字符串结果是1

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧