doudi1750 2016-11-10 09:17
浏览 8
已采纳

PHP仅在未指定值的情况下打印到表

I have some code where I am populating a table using data from a database query and a for-each loop. I have a status column, which can be one of four values - Processed, rejected, requested or cancelled.

What I need to find out is how I can make the table not include a value if it is set to processed? ($stat[Status]])

Any advice on what I should use to get this working would be much appreciated.

print "<table class='table table-bordered table-striped datatable' style='font-size:0.7em;'>";
print "<thead>";
    print "<tr>";
        print "<th>ID</th>";
        print "<th>Status</th>";
        print "<th>Title</th>";
        print "<th>First Name</th>";
        print "<th>Last Name</th>";
        print "<th>Position</th>";
    print "</tr>";
print "</thead>";
print "<tbody>";

foreach($data as $stat)

{
    print "<tr>";
        print "<td>$stat[ID]</td>";
        print "<td>$stat[Status]</td>";
        print "<td>$stat[Title]</td>";
        print "<td>$stat[FirstName]</td>";
        print "<td>$stat[LastName]</td>";
        print "<td>$stat[Position]</td>";            
    print "</tr>";
}
  • 写回答

2条回答 默认 最新

  • douxuan4556 2016-11-10 09:22
    关注
    foreach($data as $stat)
    {
        if ($stat[Status] === "processed") {
            continue;
        }
    
        print "<tr>";
        ....
    }
    

    This way you skip all 'processed' rows.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?