简体   繁体   English

如何自定义PHP中返回的MYSQL动态表行?

[英]How to customize returned MYSQL dynamic table row in PHP?

I have the following code, that creates a dynamic table with dynamic thead and tbody, the data is from a MySQL pivot table but displayed in a through php我有以下代码,它创建了一个动态表和动态表,数据来自 MySQL pivot 表,但显示在 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 specific values for example the current result being returned is:我希望能够返回特定的值,例如当前返回的结果是:

Subject主题 Mark标记 Comment评论
English Language英语 43 43 Good work好作品
English Literature英国文学 59 59 Good好的

but I want to be able to via php make the mark color red when the student has recieved 50%, how can I doo that in the $cell variable?但是我希望能够通过 php 在学生收到 50% 时使标记颜色变为红色,我该如何在 $cell 变量中做到这一点?

Use an if statement to add a class to the row, and then use CSS to make that show red.使用if语句将 class 添加到行,然后使用 CSS 使其显示为红色。

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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM