Hi all.
I am working on a script which needs to do the following.
I have a table "flightData" (table1) which holds flight records.
I have another table which holds client requests (Table2) for flight data in advance of the flight data. On the day of the flight I need "Table1" to update "Table2".
The script runs withour error BUT only the last record in "Table2" gets updated.
Can anyone please help.
Below is my complete code:
require_once('Connections/flightq.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$FlightDate = date("Y-m-d", time());
// Table2 Client data
mysql_select_db($database_flightq, $flightq);
$query_FlightClient = "SELECT * FROM flight_client";
$FlightClient = mysql_query($query_FlightClient, $flightq) or die(mysql_error());
$row_FlightClient = mysql_fetch_assoc($FlightClient);
$totalRows_FlightClient = mysql_num_rows($FlightClient);
// Table1 Flight data
mysql_select_db($database_flightq, $flightq);
$query_FlightData = "SELECT * FROM flightdata WHERE FlightDate = CURDATE()";
$FlightData = mysql_query($query_FlightData, $flightq) or die(mysql_error());
$row_FlightData = mysql_fetch_assoc($FlightData);
$totalRows_FlightData = mysql_num_rows($FlightData);
while ($row_FlightData = mysql_fetch_assoc($FlightData)){
$updateSQL = "UPDATE flight_client SET ClientAirline='".$row_FlightData['CarrierCode']."', ClientFlightNo='".$row_FlightData['FlightNumber']."', ClientFlightSuffix='".$row_FlightData['FlightSuffix']."', ClientTerminalCode='".$row_FlightData['TerminalCode']."', ClientGateNumber='".$row_FlightData['GateNumber']."', ClientFlightStatus='".$row_FlightData['FlightStatus']."', ClientFlightId=".$row_FlightData['AODBUniqueID'].", ClientStime='".$row_FlightData['ScheduledDateTime']."', ClientEtime='".$row_FlightData['EstimatedDateTime']."', ClientDepartLoc='".$row_FlightData['IATALocationCode']."', ClientArriveLoc='".$row_FlightData['PublicLocationName']."', ClientZone='".$row_FlightData['zone']."' WHERE ClientFlightNoComplete ='". $row_FlightData['FlightNoComplete']."'";
}
mysql_select_db($database_flightq, $flightq);
$Result1 = mysql_query($updateSQL, $flightq) or die(mysql_error());
mysql_free_result($FlightClient);
mysql_free_result($FlightData);