使用MYSQLI while循环使用IF / ELSE运行foreach循环

时间:2018-12-31 14:11:26

标签: php mysqli foreach while-loop

我正在使用foreach循环生成一个数组,但是要检查输入是否正确,我正在针对数据库(即While循环)对其进行检查。

但是,此代码..显然最终使所有内容都运行了两次。......

while($mp = mysqli_fetch_assoc($mappings_selected)) {
foreach ($inputdata as $key => $val) {
    $value = str_replace(array("\r", "\n", "\r\n", "\v", "\t", "\0","\x"), " ", $val);
    $pos = substr($value,0, strpos($value, ' '));
    $fnc1 = $mp['function_1'];
    $fnc2 = $mp['function_2'];
    $rank_1 = $mp['rank_1'];
    $rank_2 = $mp['rank_2'];
    $rank_3 = $mp['rank_2'];
    $usergrp = $mp['user_group'];

    if (preg_match("/^(?=.*(?:\b$fnc1\b|\b$fnc2\b))(?=.*(?:\b$rank_1\b|\b$rank_2\b|\b$rank_3\b)).*$/", $val) ){
        $usergroup = ",,,,,,,,,,,".$coursegroup.$usergrp.",";
    } else  ...... 

我的目标是运行foreach循环,然后在每次迭代中检查是否与数据库匹配,而所有代码均不运行两次...

有什么建议吗?

0 个答案:

没有答案