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.

Designing System for Gate Displays (Part I)

Hi there! Today we’re gonna to create a database for the system I’ve explained before. At the main-figure (Data flow for the system), there are two database, one refer to the airlines, and the other refer to the airport, click here to see the figure. Here, I just require to create one database refer to the airport.

If you do not have any imagine what we are going to make, just open ICCI Web. But we will not use all of variables exist there. The variables we are going to use are: Flight No., From, Time, and Status.

Well, let’s do it!

Firstly, create a new database, named ‘gatedisplays’, or others name you want to make. Or, you can just create the new table for it. Then, create a table named ‘flight’. Finish? Welldone… Then be ready for the next step. What is the next step? Alright, we are gonna create all of the variables we need. The first variable we are going to create is, ‘Flight’, then ‘From’, ‘Time’, and the last, ‘Status’. Look at the figure below.

Here is the query of the MySQL:
[php]
CREATE TABLE gatedisplays.flight (
flight VARCHAR( 7 ) NOT NULL ,
departure VARCHAR( 30 ) NOT NULL ,
time TIME NOT NULL ,
status VARCHAR( 12 ) NOT NULL ,
PRIMARY KEY ( flight )
) ENGINE = INNODB;
[/php]

Now what we have to do is, adding some data to the table to make it useful. Add 10 up to 20 data to the table as you like. Let’s get an example for it.

Ow, I forget to tell you something. As far as the flight schedule not in the range of the Gate Display, it should be an default value to the status, there is ‘unconfirmed’. That’s just my estimate. The ATC will have an authorization to change it.

Well done, in the next step we will have to do make a simple user interface for ATC to change the status while the plane is approaching the airport. And finally, make the Gate Display! ^^ . Thanks for reading.

— to be continued —

Python’s “Beautiful Heart”

Woogh!!! Maybe that words that will ‘spit out’ from your mind after try IDLE, the Python GUI, and also the Python Command Prompt. It’s so interesting to learn with, really! If you have the Mark Summerfield’s book, titled “Programming in Python 3, A Complete Introduction to the Python Language”, it will be said Python’s “Beautiful Heart”. I guess that’s why Summerfield wrote that words on the book, only guess.

Why?
First at all, you can do arithmetic operation on the IDLE. Don’t believe it? Look at the figure below.
the Python GUI (IDLE)

IDLE provides some facilities to the user, one of them is the ability to enter Python expressions to see the results directly. And that’s it! IDLE is so easy to use for experimenting a small pieces of Python code. Again, look at the figure below.
The Python GUI (IDLE)

Besides that, you also can do a simple operation using statement, such as if, while, etc. It’s makes you do an experiments with Python comes easily. Of course, it’s save your time much more. That’s it! Hope inspire you to learn Python. Hehe…

Keep in touch with Jimzland.com! 🙂