mrdarb mrdarb - 28 days ago 8
PHP Question

PHP Only print to table if is not specified value

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 appriciated.

Thanks,

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

Answer
foreach($data as $stat)
{
    if ($stat[Status] === "processed") {
        continue;
    }

    print "<tr>";
    ....
}

This way you skip all 'processed' rows.