I am new to PHP and I want to display a table from my database with each row with a different color from other rows and I tried answers and solutions similar to my question but I failed to make it done on the rows of <td><?= $field ?></td>
This my script :
<?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect('localhost','root','','class'); $mysqli->query("set names 'UTF8'"); $data = []; $res = $mysqli->query("SELECT math, physics, english FROM student order by math desc"); while ($row = $res->fetch_assoc()) { foreach(array_keys($row) as $key) { $data[$key][] = $row[$key]; } } ?> <div>student</div> <table border="1"> <?php foreach($data as $key => $val): ?> <tr> <td><?= $key ?></td> <?php foreach($val as $field): ?> <td><?= $field ?></td> <?php endforeach ?> </tr> <?php endforeach ?> </table>