php - 重复过程直到满足条件

标签 php mysql while-loop iteration do-while

我正在尝试检查要分配的类(class)和已分配给时隙的类(class)之间是否存在共同学生。

$chkcommsa = mysql_query("
    SELECT student.matric, student.std_name FROM student
    JOIN course_reg e1 ON e1.matric=student.matric
    JOIN course c1 ON c1.course_code=e1.course_code
    JOIN course_reg e2 ON e2.matric=student.matric
    JOIN course c2 on c2.course_code = e2.course_code
    WHERE c1.course_code = '".$currentass."' AND c2.course_code RLIKE '%$docamat%'
    GROUP BY student.matric") or die(mysql_error());

$num_rowea = mysql_num_rows($chkcommsa);

if($num_rowea >= 1) {

    $t_slot_times = $t_slot_time + 1;

}

如果 $t_slot_times 为 2,则查询检查要分配的当前类(class) ($currentass) 和已分配给时间段的所有其他类(class) ($docamat) 之间的普通学生2、如果是普通学生,系统将时间段递增1到3。

如果 $t_slot_times 是 3,我希望系统再次检查要分配的新类(class)和已经分配给时间段 3 的其他类(class)之间的普通学生。我只想重复在 $t_slot_times 上查询,直到查询返回 0 个结果。

最佳答案

根据您的问题,使用以下逻辑并在 $t_slot_times 为 2 且 $t_slot_times 为 3 时将您的查询添加到您希望添加的循环中

if($num_rowea >= 1) {
    $t_slot_times = $t_slot_time + 1;

    for ($i = 1;$i<=20;$i++)
    {
      //code here
     }

}

关于php - 重复过程直到满足条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30278228/

相关文章:

php - 在 php 中使用 Linux awk 命令

php - 将字符串转换为准备好的语句中的变量

mysql - 在具有来自不同表的多个值的查询子句中使用 LIKE %%

php - cakephp - Mysql 中的空白记录问题

mysql - 左/右连接问题

php - 在 PHP while 循环期间页面不会加载并且服务器崩溃

javascript - Ajax 无法正常工作

php - PHP编程语言中 'identifier'和 'reference'概念有什么区别?

c++ - while循环意味着验证用户输入不断循环

php - 检索Mysql数据并按特定顺序打印