thomasross Posted August 3, 2008 Share Posted August 3, 2008 Hi, I am currently trying to create a php database driven rostering system for my virtual airline. I am currently working from someone elses program and trying to make it suitable for our needs (this is allowed under the GNU/GPL Lisence). With virtually no PHP knowledge I have managed to tweak it almost completely to how I want it apart from one thing, adding a user's flight time onto their total flight hours. To help in your understanding of what I am trying to do, I will explain this first, and then show you the code I am trying to work from. Ok, users fly for my virtual airline using flight simulator, and submit their flight details through the rostering system (using start time, end time, locations, flight numbers and a manually entered duration). These flight details are then automatically added onto the user's total flight time (i.e. all flights they have flown) and displayed in a roster (effectively a table of all pilots and the hours they have flown). Currently the system accepts the duration as a decimal from the file a PIREP form, then adds it to the total flight hours (also a decimal) in the pirep_process and displays it in the roster as a decimal. Is there any way of altering the coding I have so that users can enter the duration as a time which can be added to their total time and displayed as a time (i.e. everything in hours and minutes). I hope this makes sense, here is the coding: pirep.php <? session_start(); header("Cache_control: private"); include 'session_checker.php'; session_checker(); include 'db.php'; include 'header.html'; echo "<p> </p>"; echo "<strong>File ".$_SESSION['username']."'s Pirep</strong><br /><br />"; $username = $_SESSION['username']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head><title>FlyintAIR Crew Centre: File a PIREP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body{font-family: Verdana; color: #cc9933} --> </style> </head> <body> <form name="form3" action="pirep_process.php" method="post"> <table cellpadding="10" cellspacing="0" align="center" style="font-size: 10pt"> <tr> <td align="left" valign="top"> </td> <td ><input name="username" type="hidden" id="username" value="<? echo "$username"; ?>"></td> </tr> <tr> <td align="left" valign="top">Date of Flight<br>("mm/dd/yy")</td> <td><input name="date" type="text" id="date" value=""></td> </tr> <tr> <td align="left" valign="top">Departure Airport<br>(ICAO)</td> <td><input name="icao_orig" type="text" id="icao_orig" value=""></td> </tr> <tr> <td align="left" valign="top">Departure Airport<br>(Airport Name)</td> <td><input name="dep_name" type="text" id="dep_name" value=""></td> </tr> <tr> <td align="left" valign="top">Arrival Airport<br>(ICAO)</td> <td><input name="icao_dest" type="text" id="icao_dest" value=""></td> </tr> <tr> <td align="left" valign="top">Arrival Airport<br>(Airport Name)</td> <td><input name="arr_name" type="text" id="arr_name" value=""></td> </tr> <tr> <td align="left" valign="top">Aircraft Type</td> <td><select name="aircraft" type="text" id="aircraft"> <option value="Airbus A318">Airbus A318</option> <option value="Airbus A319">Airbus A319-111</option> <option value="Airbus A320">Airbus A320-200</option> <option value="Airbus A321-200">Airbus A321-200</option> <option value="Airbus A330-200">Airbus A330-200</option> <option value="Boeing 717-200">Boeing 717-200</option> <option value="Boeing 737-700">Boeing 737-700</option> <option value="Boeing 737-800">Boeing 737-800</option> <option value="Boeing 757-200">Boeing 757-200</option> <option value="Bombardier CRJ200-LR">Bombardier CRJ200-LR</option> <option value="Bombardier CRJ900">Bombardier CRJ900</option> <option value="Bombardier Dash 8Q400">Bombardier Dash 8Q400</option> <option value="Embraer ERJ145-LR">Embraer ERJ145-LR</option> <option value="Embraer 170">Embraer 170</option> <option value="Embraer 190">Embraer 190</option> <option value="Fokker 70">Fokker 70</option> <option value="Fokker 100">Fokker 100</option> <option value="Saab 2000">Saab 2000</option></td> </tr> <tr> <td align="left" valign="top">Aircraft Registration<br>(e.g. G-INTX)</td> <td><input name="ac_reg" type="text" id="ac_reg" value=""></td> </tr> <tr> <td align="left" valign="top">Route Number<br>(AIRXXX)</td> <td><input name="routenum" type="text" id="routenum" value="AIR"></td> </tr> <tr> <td align="left" valign="top">Departure Time<br>(GMT/BST, 24Hr Clock Format)</td> <td><input name="dep_time" type="text" id="dep_time" value="00:00"></td> </tr> <tr> <td align="left" valign="top">Arrival Time<br>(GMT/BST, 24Hr Clock Format)</td> <td><input name="arr_time" type="text" id="arr_time" value="00:00"></td> </tr> <tr> <td align="left" valign="top">Flight Duration<br>(Decimal e.g. 1h 30 = 1.5)</td> <td><input name="flthrs2" type="text" id="flthrs2" value="0.0"></td> </tr> <tr> <td align="left" valign="top">Comments:</td> <td><textarea name="comments" id="comments"></textarea></td> </tr> <td align="left" valign="top"> </td> <td><input type="submit" name="Submit" value="File Pirep!"></td> </tr> </table> </form> </body> </html> <? echo "<p> </p>"; include 'footer.php'; ?> pirep_process.php <?php include 'db.php'; $username = $_POST['username']; $date = $_POST['date']; $icao_orig = $_POST['icao_orig']; $dep_name = $_POST['dep_name']; $icao_dest = $_POST['icao_dest']; $arr_name = $_POST['arr_name']; $aircraft = $_POST['aircraft']; $ac_reg = $_POST['ac_reg']; $routenum = $_POST['routenum']; $dep_time = $_POST['dep_time']; $arr_time = $_POST['arr_time']; $flthrs2 = $_POST['flthrs2']; $comments = $_POST['comments']; $username = stripslashes($username); $date = stripslashes($date); $icao_orig = stripslashes($icao_orig); $dep_name = stripslashes($dep_name); $icao_dest = stripslashes($icao_dest); $arr_name = stripslashes($arr_name); $aircraft = stripslashes($aircraft); $ac_reg = stripslashes($ac_reg); $routenum = stripslashes($routenum); $dep_time = stripslashes($dep_time); $arr_time = stripslashes($arr_time); $flthrs2 = stripslashes($flthrs2); $comments = stripslashes($comments); //check for empty fields if((!$date) || (!$icao_orig) || (!$icao_dest) || (!$ac_reg) || (!$routenum) || (!$dep_time) || (!$arr_time) || (!$flthrs2)){ echo 'You did not submit a complete pirep! Please be sure all fields are completed. <br />'; // Show the form again! include 'pirep.php'; exit(); } //Double flight time if an event if ($routenum == 'EVT'){ $flthrs2 = $_POST['flthrs2'] * 2; } else {$flthrs2 == $_POST['flthrs2']; } //insert info into pirep table $comments2 = htmlspecialchars($comments); $sql = mysql_query ("INSERT INTO pirep (date, username, icao_orig, dep_name, icao_dest, arr_name, aircraft, ac_reg, routenum, dep_time, arr_time, flthrs2, last_pirep, comments) VALUES('$date','$username','$icao_orig','$dep_name','$icao_dest','$arr_name','$aircraft', '$ac_reg','$routenum','$dep_time','$arr_time','$flthrs2','now()','$comments')") or die (mysql_error()); if(!$sql){ echo 'There has been an error processing your pirep. Please contact the webmaster.'; } $sql = "SELECT * FROM users WHERE username = '$username'"; $result = mysql_query($sql); $user_array = mysql_fetch_array($result); //add time to flight hours $flthrs = $user_array['flthrs']; $newflthrs = $flthrs + $flthrs2; mysql_query("UPDATE users SET flthrs = '$newflthrs' WHERE username = '$username'"); mysql_close($connection); //show user decision page include 'pirep_filed.php'; ?> pirep_filed.php <? session_start(); header("Cache-control: private"); include 'session_checker.php'; session_checker(); include 'header.html'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head><title><FlyintAIR Crew Centre: Pirep Filed</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- table{font-family: Verdana; color: #cc9933} --> </style> </head> <body> <p align="center"><font style="color: red"><strong>Your pirep has been filed!</strong></font></p> <p align="center">File another? <a href="pirep.php">Yes</a>/<a href="logout.php">No</a></p> </body> </html> <? echo "<p> </p>"; include 'footer.php'; ?> Hope you can help... Link to comment https://forums.phpfreaks.com/topic/117988-adding-time-to-time/ Share on other sites More sharing options...
natbob Posted August 16, 2008 Share Posted August 16, 2008 In the code for pirep_process.php add this right before closing the database connection: <?php $result = mysqlquery("SELECT * FROM total"); $oldnum = mysql_fetch_assoc($result); $newnum = $oldnum['total'] + $flthrs; mysql_query("UPDATE total SET total = '$newnum'"); ?> note: it uses a table named total witch has one column named total witch is an integer, it has one row, make sure that that row starts with a value of zero. Link to comment https://forums.phpfreaks.com/topic/117988-adding-time-to-time/#findComment-617969 Share on other sites More sharing options...
QuietWhistler Posted August 28, 2008 Share Posted August 28, 2008 You can also set it it more easily by using the integrated SQL math. You would then update it as follows: <?php if( is_numeric( $newnum ) ) { mysql_query( "UPDATE table SET total = total + '$flthrs'" ); } ?> Link to comment https://forums.phpfreaks.com/topic/117988-adding-time-to-time/#findComment-627904 Share on other sites More sharing options...
akitchin Posted August 28, 2008 Share Posted August 28, 2008 either i've misunderstood you, or the previous posts actually don't answer your question. just to confirm, are you asking how to edit the form so that users can input a different format (than the float) for 'flthrs2'? and then how to store and display it as hours and minutes? Link to comment https://forums.phpfreaks.com/topic/117988-adding-time-to-time/#findComment-627913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.