Designing System for Gate Displays (Final)

Hi there, ready for the next step? Alright! ^^

If you have not read the previous step, click here for the step to create the database for the system. Now, after we knew the flow of the system, create the base for the data, and here we go.

What should we do first? Create the user interface for the ATC or create the gate displays first? Better we create the gate displays first. Look at the code explained below.

[php]
//Create the header of the displays,
//here we placed no title for the displays
print("
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="20px">&nbsp;</td>
<td width="70px">Flight</td>
<td width="130px">Departure</td>
<td width="70px">Time</td>
<td width="130px">Status</td>
</tr>");

//Make a connection between your MySQL and PHP,
//change the ‘MYSQL_DB_SERVER/USER/PASSWORD/DATABASE
//based on your server setting
$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

//Get the data from the database and execute it
$getdata = "SELECT flight, departure, time, status " .
"FROM flight ORDER BY time ASC, flight ASC, departure ASC LIMIT 0, 10";
$execute = mysql_query($getdata, $connection);

//Take it into a variable and show it
while($result = mysql_fetch_array($execute)) {
$Flight = $result[0];
$Departure = $result[1];
$Time = $result[2];
$Status = $result[3];

print("
<tr>
<td>&nbsp;</td>
<td>$Flight</td>
<td>$Departure</td>
<td>$Time</td>
<td>$Status</td>
</tr>");
}
[/php]

Taadaa, and the Gate Displays ready to use ^^

Now, let’s make the user interface. The code is similarly to the code above, just need to adding some line. Have a look at figure below.

[php]
print("
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="20px">&nbsp;</td>
<td width="70px">Flight</td>
<td width="130px">Departure</td>
<td width="70px">Time</td>
<td width="130px">Status</td>
<td width="100px">&nbsp;</td> //new line added
</tr>");

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

$getdata = "SELECT flight, departure, time, status " .
"FROM flight ORDER BY time ASC, flight ASC, departure ASC LIMIT 0, 10";
$execute = mysql_query($getdata, $connection);

while($result = mysql_fetch_array($execute)) {
$Flight = $result[0];
$Departure = $result[1];
$Time = $result[2];
$Status = $result[3];

print("
<tr>
<td>&nbsp;</td>
<td>$Flight</td>
<td>$Departure</td>
<td>$Time</td>
<td>$Status</td>
<td><a href="changestatus.php?flight=$Flight">Change Status</a></td> //new line added
</tr>");
}
[/php]

Now, the view should be like this:

Look at the last line we’ve added, there is a link to ‘changestatus.php’, right? Now, let’s we make a new .php file named ‘changestatus’. We are going to using a variable passing technique called Query String. We will passing the value of the flight number to the ‘changestatus.php’ by using an addition syntax after the URL parameter, ‘?flight=$Flight’. This kind of technique passing the value from the origin file to the file that point by the URL parameter.

[php]
//Save the passing value to the new variable
$Flight = $_GET["flight"];

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

//Get the data based on passing value,
//in this case the passing value is $Flight.
//Note that $Flight is not passing value anymore,
//because it has saved in a new variable (see top code)
$getdata = "SELECT flight, status FROM flight WHERE flight = ‘$Flight’";
$execute = mysql_query($getdata, $connection);

//Show it
while($result = mysql_fetch_array($execute)) {
$Flight = $result[0];
$Status = $result[1];

print("$Flight, status: $Status");
}

//Now make the option to change the value, and send it
//pass through the URL parameter again
//Don’t forget to make a new file, named ‘dochangestatus.php’
printf("
Change status:<br>
<a href="dochangestatus.php?flight=$Flight&status=delayed">Delayed</a>&nbsp;|&nbsp;
<a href="dochangestatus.php?flight=$Flight&status=landed">Landed</a>
")
[/php]

Now, we create the ‘dochangestatus.php’ file to execute the change.

[php]
//Save the passing value to the new variable
$Flight = $_GET["flight"];
$Status = $_GET["status"];

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

$upddata = "UPDATE flight SET status = ‘$Status’ WHERE flight = ‘$Flight’";
$execute = mysql_query($upddata, $connection);

//If the query failed to execute, then the system
//will show that the operation is failed,
//if succeed, direct to the display gate file
if (empty($execute)) print("Status change failed");
else header("Location: index.php");
[/php]

Yay! Now let’s just take an experiment into its, just take one of the flight and click the ‘change status’ link, and click the ‘delayed’ or ‘landed’, and taadaa!! You’ll get this view:

You can add some line again to delete the flight after the plane landed. But, in reality, they didn’t delete the flight, but they adding a database called ‘flight history’ and store the flight schedule to the database. It’s a kind of OLAP, Online Analytical Data Processing. ^^

Please let me know if there is any question or comment that popping into your mind, or there is any idea that you want me to show up, it will be nice. But I will do it with my best and can’t promise that I can cover it all. Thanks for Micha that have this idea and let me know and I can realized her idea for all of you to get inspire. Thank you for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

*