How to implement custom returned MYSQL dynamic table rows in PHP?
P粉381463780
P粉381463780 2024-03-22 11:59:32
0
1
379

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粉381463780
P粉381463780

reply all(1)
P粉237647645

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";
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!