I'm building an Airport Taxi Booking System and as part of the table that holds the bookings there are the following columns along with other data which I don't need for this example:
Customer Name
Outbound_date
Outbound_time
Outbound_pickup
Outbound_destination
Inbound_date
Inbound_time
Inbound_pickup
Inbound_destination
I am building a page that displays all bookings between two dates inputted by the user, the results are then displayed in a HTML table with the following headings : Name, pickup, destination, date, time.
What I would like to do is build an if statement that asks if the inbound or outbound date is nearest and then displaying the journey information. I need all this in a loop for the HTML table.
I'm roughly assuming the statement would ask if outbound_date
< inbound_date
echo outbound_destination
etc... Else echo inbound_destination
etc...
This is the code I have which selects data and displays it, however it currently selects both the outbound_pickup/destination/date and the inbound versions. What I want to do is just show either the outbound/inbound columns, depending which falls between the two dates submitted by the user.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Computerised Booking System | Airport Hopper</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Daniel Green">
<link rel="stylesheet" type="text/css" href="../css/main.css"/>
<!-- Date: 2012-02-27 -->
</head>
<body>
<div id="wrapper">
<?php include('../includes/header.php');?>
<?php include('../includes/cbs_sidebar.php');?>
<div class="main-container">
<h2>Airport Hopper CBS</h2><hr/>
<?php
$db_host = 'ahopperintranet.db.8239985.hostedresource.com';
$db_user = 'ahopperintranet';
$db_pwd = '******';
$database = 'ahopperintranet';
$table = 'bookings';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT booking_ref, customer_name, outbound_destination, outbound_date, outbound_time, inbound_date FROM {$table} ORDER BY GREATEST(outbound_date, inbound_date)");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table border='1'><tr>";
?>
<tr>
<td>Booking Ref</td>
<td>Customer Name</td>
<td>Pickup</td>
<td>Destination</td>
<td>Date</td>
<td>Time</td>
</tr>
<?php
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>
";
}
mysql_free_result($result);
?>
<div class="clear"></div>
</body>