I want to run a forloop inside a while loop so that i will be able to change the colors of text accordingly. This is my code
$leftBrdColorArray = array("g-brd-blue-left", "g-brd-red-left", "g-brd-black-left", "g-brd-yellow-left");
$rowCount = $runselectGameInfo -> num_rows; //3 is the count
if($runselectGameInfo -> num_rows > 0){
while($getGameInfo = $runselectGameInfo -> fetch_assoc()){
for($i = 0; $i <= $rowCount; $i++){
Hello <div class="<?php echo $leftBrdColorArray[$i];?>">World</div>
}
}
}
But it prints 12 times insted of the rowcount i.e 3.
whileloop runs twice. For each run theforloop runs 3 times.$runselectGameInfo -> fetch_assoc()have 2 results in it. make anechostatement inside thewhileloop but outside theforloop to test how many times it runsforloop runs for the values of$istarting from 0 to 3 inclusive, that is 4 times. Are you sure you get the printing 6 times ?