php change background color of cell based on sql table number
First question here on stack, also very new to php as you can probably
tell from my code below. What im trying to do is populate information from
a database onto a page. It appears in table format and users can search
for specific records by one or more filters. What id like to do is have
the 'age' filter show the record with a different color background
depending on the age. It will work for one, as in it will show all users
whose ages are less than 22 with an orange background. What id like it to
do (and I think this is the part where I just dont understand the syntax
yet) is to display all records whose ages are less than 19 with a Red
background AND all records whose ages are less than 22 with an Orange
background.
What im trying to say in the code below is if the row record for 'age' is
less than 22, give the table row a background color of ffab0a, if its less
than 19 give the table row a background color of ffff99, anything else, no
background color.
Can anyone help point me in the right direction? below is the part that
controls this thanks!
if ($row["age"]<22)
echo '<tr style="background-color:#ffab0a">';
else if ($row["age"]<19)
echo '<tr style="background-color:#ffff99">';
else
echo '<tr>'; ?>
<td><?php echo $row["age"]; ?></td>
<td><?php echo $row["location"]; ?></td>
<td><?php echo $row["form"]; ?></td>
No comments:
Post a Comment