简体   繁体   中英

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. 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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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