I have the following code, which creates a dynamic table with a dynamic thead and tbody, with data coming from a pivot table in MySQL, but displayed via php:
while($row = $res->fetch_row()) { echo "<tr>"; foreach($row as $cell) { // dd($row); if ($cell === NULL) { $cell = '-'; } echo "<td>$cell</td>"; } echo "</tr>\n"; }
I want to be able to return a specific value. For example, the currently returned result is:
suject | Fraction | Comment |
---|---|---|
English language | 43 | a good job |
English Literature | 59 | good |
But when the student gets 50%, I want to mark the score as red through php, how can I achieve this function in the $cell variable?
P粉2376476452024-03-23 00:56:24
Add a class to the row using a if
statement and use CSS to display it red.
while($row = $res->fetch_row()) { if ($row['mark'] <= 50) { $class = 'class="red"'; } else { $class = ''; } echo "<tr $class>"; foreach($row as $cell) { // dd($row); if ($cell === NULL) { $cell = '-'; } echo "<td>$cell</td>"; } echo "</tr>\n"; }