Forum Moderators: coopster

Message Too Old, No Replies

PHP/MySQL IF Help

         

mambo

6:37 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



Hey guys.

I'm completely new to PHP and so far its been a bit of a bumpy ride. I am currently trying to produce a script that will display a timetable, and highlight the flights within the next hour in bold ($isBold). I have gone as far as i can but cant find any reference material.

Here is the script I have come up with, and I have included a basic outline of what I want to do, but I am struggling to find the correct syntax for it. Any help would be hugely appreciated.

Kind Regards

Mambo

<?php
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("airline", $con);

$result = mysql_query("SELECT * FROM flights ORDER BY DepartureTime");

print time();
$currtime = time();

$isBold=0
if( $currtime <= $row['DepartureTime'] AND $currtime+60*60*1000 > $row['DepartureTime'])
echo $isBold[$mesiac[0]-1];
$isBold=1
else
write Flight Details
if ($IsBold==1) write close Bold

echo "<table border='1'>
<tr>
<th>Flight Number</th>
<th>Departing</th>
<th>Arriving</th>
<th>Departure Time</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FlightNumber'] . "</td>";
echo "<td>" . $row['DepartingFrom'] . "</td>";
echo "<td>" . $row['ArrivalAt'] . "</td>";
echo "<td>" . $row['DepartureTime'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

cameraman

10:07 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, mambo. You're pretty close.
It's a little tidier if you use CSS (put this part in the head of the document, of coures):
<style type="text/css">
.highlight td { font-weight: bold; }
</style>

Remove your bold stuff, then figure it out inside the while - I've simplified your math a little, and time() doesn't go to milliseconds so the 1000 is out:
while($row = mysql_fetch_array($result))
{

$leaving = $row['DepartureTime'] - $currtime;
if(($leaving > 0) && ($leaving <= 3600))
$class = 'highlight';
else
$class = '';

echo "<tr class=\"$class\"";