我在 MySQL
中使用 Php
建立了一个数据库。我获取它并以表格形式显示它。
我试图在两个条件下用特定颜色突出显示数据:
条件 1:- 年龄大于 24 (颜色为#FF7676)红色
条件 2:- 年龄小于 20 (颜色为 #F8FF00)黄色
但是当我所有的数据都是黄色的时候
<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>
请帮助我,代码无法正常工作。
最佳答案
你的问题在这里
if($age>24)
{
$class='grater';
}
if($age<20)
{
$class='small';
}
会是
if($emp_age>24)
{
$class='grater';
}
else if($emp_age<20)
{
$class='small';
}
关于php - 在 php 中根据年龄使用特定颜色突出显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997134/