0

私は空港タクシー予約システムを構築しています。予約を保持するテーブルの一部として、この例では必要のない他のデータとともに次の列があります。

Customer Name 
Outbound_date
Outbound_time
Outbound_pickup
Outbound_destination

Inbound_date
Inbound_time
Inbound_pickup
Inbound_destination

ユーザーが入力した 2 つの日付の間のすべての予約を表示するページを作成しています。結果は、名前、ピックアップ、目的地、日付、時間の見出しを持つ HTML テーブルに表示されます。

私がやりたいのは、インバウンドまたはアウトバウンドの日付が最も近いかどうかを尋ねる if ステートメントを作成してから、旅の情報を表示することです。HTMLテーブルのループでこれらすべてが必要です。

私は大まかに、ステートメントが if outbound_date< inbound_date echo outbound_destinationetc... Else echo inbound_destinationetc...を尋ねると仮定しています。

これは、データを選択して表示するコードですが、現在、outbound_pickup/destination/date と受信バージョンの両方を選択しています。私がやりたいことは、ユーザーが送信した2つの日付の間にどちらが入るかに応じて、アウトバウンド/インバウンドの列のいずれかを表示することです.

<!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>\n";
}
mysql_free_result($result);
?>
<div class="clear"></div>
</body>
4

0 に答える 0