jeudi 23 avril 2020

IF statement returning error, I can't work out why

I want it to change the background colour of any row which has a value "Destroyed" in the "STATUS" column. I'm unsure how to do the IF statement.

Column STATUS value will either be either "Donotuse" or "Usebydate" or "Destroyed"

If it's Destroyed I want a different background. There are very few of these and the background is already toggled for readability, so it has to overwrite the toggled background. Also the first column is a button, so I don't want to change that unless I have to. I'd be fine with just changing the cell background colour if thats easier/more efficient. This is what is in the example after I totally broke everything else. Everything works fine without the extra IF statement.

I'm attempting to use this questions accepted answer as a basis, but can't get it working Similar problem

$sql = 'select *
          from vegetables
         order by veg_id desc;
$stmt = $dbh->prepare($sql);
$stmt->execute();
}

$toggle = true;
while (true) {
$r = $stmt->fetch();
if (is_bool($r)) break;

$toggle = !$toggle;

if ($toggle) print '<tr bgcolor="#EEEEEE">' . "\n";
else print '<tr>' . "\n";

print '
    <td class="buttonR" onclick="open(' . $r['veg_id'] . ');">' . $r['veg_id'] . '</td>
    <td class="cellL">' . $r['name'] . '</td>
    <td class="cellL">' . ucwords($r['status']) . '</td>;
    {if ($r['status']=='Destroyed')
    {
    print '<tr bgcolor="#FF0000">' . "\n";
}}
    <td class="cellL">' . ucwords($r['type']) . '</td>
    </tr>' . "\n";
}

dbh_free($dbh);

Aucun commentaire:

Enregistrer un commentaire