0

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

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

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.

0

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.

0

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

0

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

0

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>";
                    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.