简体   繁体   English

虽然只循环一次“PHP/MYSQL”

[英]While loop only once "PHP/MYSQL"

For a school task i am working on I've been writing a while loop which should loop until the condition is reached, but when i launch the website it doesn't go until the condition is met is just loops once.对于我正在处理的一项学校任务,我一直在编写一个 while 循环,它应该循环直到达到条件,但是当我启动网站时,它不会运行,直到满足条件才循环一次。 Does anyone know why this could happen?有谁知道为什么会发生这种情况?

Code:代码:

function Som($Pdo){
    $Stmt4 ='';
    $Stmt5 ='';
    $Tetter ='nee';
    while($Tetter == 'nee'){
        $I = 1;
        $I++;
        echo $I;    
        $Stmt = $Pdo->query('SELECT max(OpdrachtID) AS opdracht FROM opdracht ');
        $QuestionID = $Stmt->fetch();
        $Rand = rand(1, $QuestionID['opdracht']);
        $Stmt2 = $Pdo->query("SELECT Opdracht FROM opdracht WHERE OpdrachtID =".$Rand." AND GroepID = 2 AND OpdrachtSoort = 'Multi'");
        $D1 = $Stmt2->fetch();
        $Opdracht = $D1['Opdracht'];
        $Stmt3 = $Pdo->query("SELECT Antwoord FROM opdracht WHERE OpdrachtID ='.$Rand.' AND GroepID = 2 AND OpdrachtSoort = 'Multi'");
        $D2 = $Stmt3->fetch();
        $Stmt4 = $Pdo->query('SELECT GroepID FROM opdracht WHERE OpdrachtID ='.$Rand);
        $Stmt5 = $Pdo->query('SELECT OpdrachtSoort From opdracht WHERE OpdrachtID ='.$Rand);
        $Antwoord = $D2['Antwoord'];
        $S89 = $Stmt4->fetch();
        $S8 = $S89['GroepID'];
        $S98 = $Stmt5->fetch();
        $S9 = $S98['OpdrachtSoort'];
        #echo $S8;

        #echo $S9;

        $returnWaarde['vraag'] = $Opdracht;
        echo $returnWaarde['vraag'];
        $returnWaarde['antwoord'] = $Antwoord;
        if($S8 == 2 && $S9 == 'Multi'){
            $Tetter = 'ja';
            echo $Tetter;

        }
        else{
            $Tetter = 'nee';
            echo $Tetter;
        }
        return $returnWaarde;
        }

}

There are multiple bits of code here showing if everything is working correct, of which.这里有多位代码显示是否一切正常,其中。 $I is always 2. $Tetter sometimes shows 'ja' but most of the time 'nee' $I 总是 2. $Tetter 有时显示 'ja' 但大部分时间显示 'nee'

I know it's a bit messy but I've been working on this one part for a while now.我知道这有点乱,但我已经在这一部分工作了一段时间。

I would probably make all in one select, but ok.我可能会在一个选择中选择所有内容,但是可以。

Your您的

return $returnWaarde;

Is in the While loop it must be be after the closing paragenesis of the while loop.在 While 循环中,它必须在 while 循环的关闭共生之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM