Hi guys great site by the way.
ok I have a question well more than one but for now I need to ask this if I stor information in a mysql databse using the time format 00:00:00 can this be used to add up hours the problem I have is this I use software to grab information from flight simulator that sends to a php form so basically its posting then adding to a databse. this is all well and works fine it creates a new entry for every flight that is entered no problem . But what I wish to do or would like to try and do is this also send the information to another datbase and have the time add onto the time you have already logged in this field.Remebering that the code for the software must remain the same or the $POST[xxxx] must remain the same i have attempted to write a script to do this but php time is my nemisis.I have highlighted my addin code in red I know im wrong here as I have seen $variable= $something + $something adding two together but am unsure of how this is done in order to make the time add to the already recorded time in that other database sorry this post is so long if you can help or point me in the right direction that would be great.
thanks in advance
Lee
<?php
// ALL IS OK REGISTER THE FLIGHT
$query = "INSERT INTO flights(id,datestamp,UserName,CompanyName,PilotName,FlightId,OnlineNetworkNbr,FlightDate,AircraftName,AircraftType,NbrPassengers,CargoWeight,Mtow,StartAircraftWeight,EndAircraftWeight,StartFuelQuantity,EndFuelQuantity,DepartureIcaoName,ArrivalIcaoName,DepartureLocalHour,ArrivalLocalHour,DepartureGmtHour,ArrivalGmtHour,TotalBlockTime,TotalBlockTimeNight,TotalAirbornTime,TotalTimeOnGround,TotalDistance,MaxAltitude,CruiseSpeed,CruiseMachSpeed,CruiseTimeStartSec,CruiseTimeStopSec,CruiseFuelStart,CruiseFuelStop,LandingSpeed,LandingPitch,TouchDownVertSpeedFt,CaptainSentMayday,CrashFlag,FlightResult,PassengersOpinion,PassengersOpinionText,FailureText,CasualtiesText,PilotBonusText,BonusPoints,PilotPenalityText,PenalityPoints) VALUES('',now(),'$_POST[UserName]','$_POST[CompanyName]','$_POST[PilotName]','$_POST[FlightId]','$_POST[OnlineNetworkNbr]','$_POST[FlightDate]','$_POST[AircraftName]','$_POST[AircraftType]','$_POST[NbrPassengers]','$_POST[CargoWeight]','$_POST[Mtow]','$_POST[StartAircraftWeight]','$_POST[EndAircraftWeight]','$_POST[StartFuelQuantity]','$_POST[EndFuelQuantity]','$_POST[DepartureIcaoName]','$_POST[ArrivalIcaoName]','$_POST[DepartureLocalHour]','$_POST[ArrivalLocalHour]','$_POST[DepartureGmtHour]','$_POST[ArrivalGmtHour]','$_POST[TotalBlockTime]','$_POST[TotalBlockTimeNight]','$_POST[TotalAirbornTime]','$_POST[TotalTimeOnGround]','$_POST[TotalDistance]','$_POST[MaxAltitude]','$_POST[CruiseSpeed]','$_POST[CruiseMachSpeed]','$_POST[CruiseTimeStartSec]','$_POST[CruiseTimeStopSec]','$_POST[CruiseFuelStart]','$_POST[CruiseFuelStop]','$_POST[LandingSpeed]','$_POST[LandingPitch]','$_POST[TouchDownVertSpeedFt]','$_POST[CaptainSentMayday]','$_POST[CrashFlag]','$_POST[FlightResult]','$_POST[PassengersOpinion]','$_POST[PassengersOpinionText]','$_POST[FailureText]','$_POST[CasualtiesText]','$_POST[PilotBonusText]','$_POST[BonusPoints]','$_POST[PilotPenalityText]','$_POST[PenalityPoints]')";
if(!@mysql_query($query)){echo "#Answer# SQL Error - ".mysql_error();return;}
[COLOR=Red]
[B]$pilot_id=$_POST["UserName"];
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydatabse");
$query = mysql_query("SELECT hours FROM members WHERE pilot_id ='$pilot_id'") or die (mysql_error());
$row_query = mysql_fetch_assoc($query);
$Calculatetime=AddTime($row[hours],$_POST[TotalBlockTime]);
mysql_query("UPDATE members SET hours='$Calculatetime' WHERE pilot_id='$pilot_id'")
or die (mysql_error());[/[/B]COLOR]
function AddTime($Time1,$Time2)
{
$timea=explode(":",$Time1);
$timeb=explode(":",$Time2);
$secondes=($timea[0]+$timeb[0])*3600;
$secondes+=($timea[1]+$timeb[1])*60;
$secondes+=$timea[2]+$timeb[2];
$hours = floor($secondes / 3600);
$minute = floor(($secondes - ($hours * 3600)) / 60);
$secconde = $secondes - ($hours * 3600) - ($minute * 60);
return sprintf("%02d:%02d:%02d", $hours, $minute, $secconde);
}
?>