I've been trying to list 9 tables for each student using the following code -
Up to 8 records are getting successfully printed. But for the next value of $s, the next student gets listed.
Where am I getting it wrong?
$query="SELECT * FROM `member_db` WHERE Class='$class' ORDER BY `Member_name` ASC";
$Result = mysqli_query($conn, $query);
$s=1;
while($row=mysqli_fetch_array($Result)) {
foreach($row as $field) {
if($s==10){
$s=1; break;
} else if($s==1){
$sub="English (WS VOL-1)";
} else if($s==2){
$sub="English (WS VOL-2)";
} else if($s==3){
$sub="English (WS VOL-3)";
} else if($s==4){
$sub="Maths (WS VOL-1)";
} else if($s==5){
$sub="Maths (WS VOL-2)";
} else if($s==6){
$sub="Maths (WS VOL-3)";
} else if($s==7){
$sub="Science (WS VOL-1)";
} else if($s==8){
$sub="Science (WS VOL-2)";
} else if($s==9){
$sub="Science (WS VOL-3)";
}
echo $table;
$s++;
}
}
try this : $i++ should be after end inner loop.
<?php
$query = "SELECT * FROM `member_db` WHERE Class='$class' ORDER BY `Member_name` ASC";
$Result = mysqli_query($conn, $query);
$s = 1;
while ($row = mysqli_fetch_array($Result)) {
foreach ($row as $field) {
if ($s == 10) {
$s = 1;
break;
}
if ($s == 1) {
$sub = "English (WS VOL-1)";
} elseif ($s == 2) {
$sub = "English (WS VOL-2)";
} elseif ($s == 3) {
$sub = "English (WS VOL-3)";
} elseif ($s == 4) {
$sub = "Maths (WS VOL-1)";
} elseif ($s == 5) {
$sub = "Maths (WS VOL-2)";
} elseif ($s == 6) {
$sub = "Maths (WS VOL-3)";
} elseif ($s == 7) {
$sub = "Science (WS VOL-1)";
} elseif ($s == 8) {
$sub = "Science (WS VOL-2)";
} elseif ($s == 9) {
$sub = "Science (WS VOL-3)";
}
echo $table;
}
$s++; //this is only change
}