mandar262 mandar262 - 2 months ago 6
CSS Question

To highlight the data acording to age with specific color in php

I have a database in

MySQL
using
Php
. I fetch it and display it in table form.

I was trying to highlight the data with specific color with two conditions:

Condition 1:- whose age is grater than 24 (color is #FF7676) red

Condition 2:- whose age less than 20 (color is #F8FF00) Yellow

but when my all data is in yellow color

<html>
<head>
<title>DataBase of Age</title>
<link rel="stylesheet" href="bootstrap-3.3.1-dist/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-3.3.1-dist/dist/css/bootstrap-theme.min.css">
<script src="bootstrap-3.3.1-dist/dist/js/bootstrap.min.js">
</script>
<style>
.grater
{
background-color:#FF7676;
}
.small
{
background-color:#F8FF00;
}
</style>
</head>
<body>
<table class="table">
<tr>
<td>#</td>
<td>Name</td>
<td>Age</td>
<td>City</td>
<td>Post</td>
<td>Salary</td>
</tr>
<?php
$connection=mysqli_connect('localhost','root','','db_employee') or die(mysqli_connect_error());
echo"DataBase Connection Establish Successfully...!!!";
$q=mysqli_query($connection,'select * from tbl_information');
echo"Total number of record found are:-".mysqli_num_rows($q);
$age=1;
while($table=mysqli_fetch_assoc($q))
{
extract($table);
$class=null;
if($age>24)
{
$class='grater';
}
if($age<20)
{
$class='small';
}
$age++;
?>
<tr class="<?=$class?>">
<td><?=$emp_id?></td>
<td><?=$emp_name?></td>
<td><?=$emp_age?></td>
<td><?=$emp_city?></td>
<td><?=$emp_post?></td>
<td><?=$emp_salary?></td>
</tr>
<?php
}
?>
</table>
</body>




Please help me the code is not working.

Answer
if($age>24)
{
   $class='grater';
}
if($age<20)
{
   $class='small';
}

It will be

if($emp_age>24)
{
   $class='grater';
}
else if($emp_age<20)
{
  $class='small';
}