按状态为表格行着色

我想if在我的状态字段中进行操作。如果我的状态是“阻止”,那么字体背景颜色将为红色,如果状态为“授权”,则为绿色。


我该怎么做?


    foreach($data as $row)

   {

    $output .= '

    <tr>


     <td>'.$row->client_name.'</td>

     <td>'.$row->adrress.'</td>

     <td>'.$row->occupation.'</td>

     <td>'.$row->payeee.'</td> 

     <td>'.$row->status.'</td> 



    </tr>

    ';

   }


牧羊人nacy
浏览 133回答 3
3回答

千巷猫影

您真的不应该在控制器中处理视图逻辑。但是要在控制器中做你想做的foreach($data as $row){&nbsp; &nbsp; $output .= '&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp;<td>'.$row->client_name.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->adrress.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->occupation.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->payeee.'</td>';&nbsp; &nbsp; &nbsp;if($row->status == "bad"){&nbsp; &nbsp; &nbsp; &nbsp; $output .= '<td style="background-color:red;">'.$row->status.'</td>';&nbsp; &nbsp; &nbsp;} else if($row->status == "good") {&nbsp; &nbsp; &nbsp; &nbsp;$output .= '<td style="background-color:green;">'.$row->status.'</td>';&nbsp; &nbsp; }&nbsp; &nbsp; $output .= '</tr>';}但是你应该做的是在你的刀片文件中处理它。此外,您可能希望在样式表中创建样式并应用类而不是内联 css。

月关宝盒

尝试这个foreach($data as $row){$output .= '<tr>&nbsp;<td>'.$row->client_name.'</td>&nbsp;<td>'.$row->adrress.'</td>&nbsp;<td>'.$row->occupation.'</td>&nbsp;<td>'.$row->payeee.'</td>&nbsp;&nbsp; &nbsp;@if($row->status == "blocked")&nbsp; &nbsp;<td> <button type="button" class="btn btn-danger">blocked</button> </td>&nbsp; &nbsp;@elseif($row->status == "authorized")&nbsp; &nbsp;<td> <button type="button" class="btn btn-success">authorized</button> </td>&nbsp; &nbsp;@endif&nbsp;</tr>或者foreach($data as $row){&nbsp; &nbsp; $output .= '&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp;<td>'.$row->client_name.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->adrress.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->occupation.'</td>&nbsp; &nbsp; &nbsp;<td>'.$row->payeee.'</td>';&nbsp; &nbsp; &nbsp;if($row->status == "bad"){&nbsp; &nbsp; &nbsp; &nbsp; $output .= '<td style="background-color:red;">'.$row->status.'</td>';&nbsp; &nbsp; &nbsp;} else if($row->status == "good") {&nbsp; &nbsp; &nbsp; &nbsp;$output .= '<td style="background-color:green;">'.$row->status.'</td>';&nbsp; &nbsp; }&nbsp; &nbsp; $output .= '</tr>';}

幕布斯7119047

这是有效的代码foreach($data as $row){$output .= '<tr>&nbsp;<td>'.$row->client_name.'</td>&nbsp;<td>'.$row->adrress.'</td>&nbsp;<td>'.$row->occupation.'</td>&nbsp;<td>'.$row->payeee.'</td>';&nbsp;if($row->status == "bad"){&nbsp; &nbsp; $output .= '<td style="background-color:red;">'.$row->status.'</td>';&nbsp;} else if($row->status == "good") {&nbsp; &nbsp;$output .= '<td style="background-color:green;">'.$row->status.'</td>';}$output .= '</tr>';}
打开App,查看更多内容
随时随地看视频慕课网APP