samedi 31 octobre 2015

two if inside an if inside a foreach not working properly

I have two ifs inside an if. They're not showing in the order that I want.

I want the if:

if(${'user'.$countCats}[$resp->getQuestionId()]...

shows first and then the if:

if($resp->getIdR()==${'bd'.$countCats}[$resp->getQuestionId()])....

If someone can help thank you!

Here's the code:

<?php
function afficheResultats(Array $user1,Array $user2,Array $user3,
                      Array $bd1,Array $bd2,Array $bd3,
                      $tableCats,$tableQ, $tableR)
{
echo "Évaluation: ";
$pourcTous=0;
$countCats=0;
foreach ($tableCats as $categ) 
    {
        $countGoods=0;
        $countBads=0;
        $countCats++;
        {                   
            echo " ".$categ." ";
            foreach ($tableQ as $quest) 
            {
                if($quest->getCatId()==$categ->getIdCat())
                {
                    echo $quest;                        
                    foreach ($tableR as $resp) 
                    {   

                        $contenu="";                        

                        if($resp->getQuestionId()==$quest->getIdQ()
                           &&$resp->getIdCat()==$categ->getIdCat())
                            {
                                $eval=false;

                                if($resp->getIdR()==${'user'.$countCats}[$resp->getQuestionId()])
                                {
                                    $contenu= "<p>Votre réponse: ".$resp->getNameR()."<p/> ";
                                    //$eval=false;
                                    if(${'user'.$countCats}[$resp->getQuestionId()]==${'bd'.$countCats}[$resp->getQuestionId()])
                                    {                                       
                                        $contenu.="<p>Correct!</p>";
                                        $eval=true;
                                        $countGoods++;                                          
                                    }
                                    else
                                    {
                                        $contenu.="<p>Incorrect.</p> ";
                                        $eval=false;
                                        $countBads++;
                                    }
                                }
                            }
                        if($resp->getQuestionId()==$quest->getIdQ()
                           &&$resp->getIdCat()==$categ->getIdCat())
                            {                               
                                if($resp->getIdR()==${'bd'.$countCats}[$resp->getQuestionId()])
                                {
                                    $contenu.="<p>Bonne réponse: ".$resp->getNameR()."<p/>";
                                }                                                                   
                            }   

                    }
                    echo $contenu;
                }
            }
            $pourcPartial=round($countGoods/($countGoods+$countBads)*100);
            echo "<p> Pourcentage pour cette parti: ".$pourcPartial."%</p>";
            $pourcTous+=$pourcPartial;              
        }           
    }       
    echo " <p>Pourcentage Total: ".round($pourcTous/$countCats)."%</p>";
}

Aucun commentaire:

Enregistrer un commentaire