I trying fetchd data from database with array. but when i combine foreach inside while, it looping as much data in database. how to stop looping ? i already make break function but not work. what is missing from my code.
here is mycode :
<?php
$no=1;
if(mysqli_num_rows($query) > 0)
{
$useArray = array("A","B","B","C");
while($row = mysqli_fetch_array($query))
{
foreach ($useArray as $array)
{
echo"<tr>";
echo "<td>".$no."</td>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['grade']."</td>";
if($row['v1']>=2.000)
echo "<td class='bg-success'>".$row['v1']."</td>";
elseif($row['v1']>=1.500)
echo "<td class='bg-warning'>".$row['v1']."</td>";
elseif($row['v1']>=0.100)
echo "<td class='bg-danger'>".$row['v1']."</td>";
else
{
echo "<td class='bg-dark'>".$row['v1']."<h5>D</h5></td>";
}
echo "<td>".$array."</td>";
if ($array == "C") {
break;
}
echo "</tr>";
}
$no++;
}
}
else
{
?>
</tbody>
</table>
<?php
echo "No Point";
}
?>
the result like below
i do searching first, but not working. maybe i'm wrong implementing the code. here is my reference : Combining foreach and while in PHP , break out of if and foreach.
my expected result is :
total data is fixed with how much string in array, so if in array is ("A","B","B","C") so in database also just 4 rows. any help is apreciated.