PHP Time Help

I’m currently editing a system called RadiPanel and i’m having a few problems, so I thought I’d come over to this forum. Basically I have a code and so far I’ve managed to get it to fetch from the database no problem, but I’m needing a little guidance.

I’m trying to get the code to display the

in a different format depending on an event has happened, happening or is going to happen (Past Present + Future)

[php]<?php
require_once(“staff/_inc/glob.php”);

$today = date('N');

$query = $db->query("SELECT * FROM `events` WHERE day = '{$today}' ORDER BY `time` ASC");
$num   = $db->num($query);

if (!$num == "0") {

    	        echo "<table width=\"100%\" cellpadding=\"3\" cellspacing=\"1\">";
    	        echo "<tbody>";

    	        echo "<tr style=\"background: #CECECE; font-weight: bold;\">";
    	        echo "	<td style=\"background: #D6D6D6; color: #6E6E66; padding: 3px; text-align: center;\"><strong>Event Name</strong></td>";
    	        echo "	<td style=\"background: #D6D6D6; color: #6E6E66; padding: 3px; text-align: center;\"><strong>Host</strong></td>";
    	        echo "	<td style=\"background: #D6D6D6; color: #6E6E66; padding: 3px; text-align: center;\"><strong>Time</strong></td>"; 
        	echo "</tr>"; 
           	
            	while ($fetch = $db->assoc($query))

		  $time = `time`;
		  $now = date("H:i:s"); 
		  $now_plus_one = date("H:i:s")+1;

			{
			if( $time < $now ) {

                    	        echo "<tr style=\"background: #d6d6d6; color: #bfbfbf;\">";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['name']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['host']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['time']}</td>";
                    	        echo "</tr>";

			} elseif ( $time >= $now and $time <= $now_plus_one ) {

                    	        echo "<tr style=\"background: #CECECE; color: #595953;\">";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['name']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['host']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['time']}</td>";
                    	        echo "</tr>";

			} else {

                    	        echo "<tr style=\"background: #D6D6D6; color: #6E6E66;\">";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['name']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['host']}</td>";
                    	        echo "	<td style=\"padding: 3px; text-align: center;\">{$fetch['time']}</td>";
                    	        echo "</tr>";

			} 

	            	}

    	        echo "</tbody>";
    	        echo "</table>";

}


else {

                echo "<br/><br/><center>No events.</center><br/>";

}

?>[/php]

This is my code, I hope someone can help me, I’m aware some vars are unidentified, thats because I havn’t a clue what to put at them.

I used just TIME in my sql so time shows as 18:00:00 etc.

Is this what you’re trying to do with $now_plus_one?

[php]
echo date(“H:i:s”) . PHP_EOL;
echo date(“H:i:s”)+1 . PHP_EOL;

//Outputs:
//10:21:32
//11
[/php]

$time you’re setting to a value of ‘time’… then when you compare against it with $time >= $now, you’re essentially saying “if ('time” >= 10:31:30)" - clearly not going to work :wink: Try instead,

[php]

$time = $num[‘time’];

if ($time >= $now) { …}

[/php]

But you’re on the right track and the code looks to be OK. It’s likely that there’s a variable with an unexpected or null value. Try echoing them all to check.

You could also clean up the code with something like:

[php]

// Default
$color = ‘#d6d6d6;’;

if ( $time >= $now and $time <= $now_plus_one ) {
$color = ‘#cecece;’;
}

echo ’

"; ' . $fetch['name']. ' ' . $fetch['host'] . ' ' . $fetch['time'] . '"; ';

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service