Hi everybody,
i make page which display all the record of the user in a table,i want to check if the time of the user login is great than 9:15 am the row background must be red,
if not the normal white sisplay,
i have the following script but not working fine

while ($rc = mysql_fetch_array($my)) 
                    {
    
                    
                        //Display the data in HTML tables
                   //     while ($re = mysql_fetch_array($rd)) {
                             ?>
                       	<tr <?php if(($rc['arrival_at']>='9:15 am')||($rc['arrival_at']>='09:15 am')){echo "style='font-weight:bold; background-color:red'";} else {echo "style='background-color:#DDDDDD'";} ?> >    
                        <?php 
                        echo "<td>" . $rc['user_name'] . "</td>";
                   //     }
                        echo "<td>" . $rc['date'] . "</td>";
                        echo "<td>" . $rc['arrival_at'] . "</td>";
                        echo "<td>" . $rc['left_at'] . "</td>";
                        echo "<td >" . $rc['late_reason'] . "</td>";
                        echo "<td >" . $rc['system_ip'] . "</td>";
                        echo "</tr>";
                    }

it show the background red only for the 9 am not working for 10 am

Recommended Answers

All 5 Replies

It is my suggestion that ,
for these type of caluculations ,better use time in particular format(minutes) while saving in mysql.like :
12.00 am - 0
1.00 am - 60
2.00 am - 120
. .
. .
12.00 pm - 720
13.00 pm - 780
. .
. .
. .
24.00 pm - 1440

so that you can easily compare you timings like wise.

what is the datatype of arrival_at, its datetime or time or varchar.

If its varchar then you need to cast it to time before comparing. So mention here how you store your arrival_at.

the datatype of the arrival_at is varchar,
and this part of the database is upload, i am unable to change any thing in the database,
kindly help me how i manage this table with different colors

Are you sure all columns are in the format hh:mi am/pm or or does it somewhere exist time in 24 hour format.

I have added new php code in <tr> tag

while ($rc = mysql_fetch_array($my)) 
                    {
    
                    
                        //Display the data in HTML tables
                   //     while ($re = mysql_fetch_array($rd)) {
                             ?>
                       	<tr
						   
						   <?php
						   
						$arrival=strtotime($rc['arrival_at']);
						$deadlinetime=strtotime('9:15 am');

					   if($arrival>$deadlinetime || date("d-m-y",$arrival)=="01-01-70")//second condition is if time is not in valid format
					   {
					    	echo "style='font-weight:bold; background-color:red'";
						} 
						else 
						{
						 echo "style='background-color:#DDDDDD'";
						} ?> 
						
						>  
						   
						   
						       
                        <?php 
                        echo "<td>" . $rc['user_name'] . "</td>";
                   //     }
                        echo "<td>" . $rc['date'] . "</td>";
                        echo "<td>" . $rc['arrival_at'] . "</td>";
                        echo "<td>" . $rc['left_at'] . "</td>";
                        echo "<td >" . $rc['late_reason'] . "</td>";
                        echo "<td >" . $rc['system_ip'] . "</td>";
                        echo "</tr>";
                    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.