Thursday, June 7, 2012

Aged people are in different color php mysql

Aged people are in different color php mysql

This lessen  shows you people whose age>=57 in red color. I used the person table created for previous lessen
The final table is like bellow.


Production Division
ID Division Name Age
1 Scarl Johan 63
2 Clooneer Henderson 38
3 Katena Daviddson 62
4 Mark Jones 57
5 Silvi James 42
6 Jerry Harfer 25
7 Mark Header 57
8 Kim Darrel 22
9 Tiny Dare 61

php codes to display above file is

<?php
echo "<center><table bgcolor=#0b2d04>
<tr bgcolor=#e6f293><td colspan=9 align='center'>Production Division</td></tr>
<tr bgcolor=#327423>
<th><font color=#ffffff>ID</font></th>
<th><font color=#ffffff>Division</font></th>
<th><font color=#ffffff>Name</font></th>
<th><font color=#ffffff>Appointed Date</font></th>
</tr>";
$host="localhost";
$username="root";
$password="";
$db_name="my_database";
$tbl_name="person";


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT id,FirstName,LastName,year(curdate())-year(birth_day) as Age FROM $tbl_name";

$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
if ($row['Age'] >= 57)
            {
                echo "<tr  bgcolor=#e6f293>
<td><font color='red'>".$row['id']."</font></td>
<td><font color='red'>".$row['FirstName']."</font></td>
<td><font color='red'>".$row['LastName']."</font></td>
<td><font color='red'>".$row['Age']."</font></td>

</tr>";
            } else
            {
               echo "<tr  bgcolor=#e6f293>
<td>".$row['id']."</td>
<td>".$row['FirstName']."</td>
<td>".$row['LastName']."</td>
<td>".$row['Age']."</td>

</tr>";
}
}
echo "</table>";
  ?>

No comments:

Post a Comment