gpt4 book ai didi

php - 如何访问同名的PHP表元素

转载 作者:行者123 更新时间:2023-11-29 12:36:42 26 4
gpt4 key购买 nike

我有这个 SQL 查询

   $query="SELECT * FROM FLIGHTTABLE INNER JOIN AirplaneTable ON FLIGHTTABLE.AIRPLANEID = AirplaneTable.AIRPLANEID
INNER JOIN AIRPORTTABLE from_airport ON FLIGHTTABLE.AIRPORTDEPARTURE = from_airport.AIRPORTID
INNER JOIN AIRPORTTABLE to_airport ON FLIGHTTABLE.AIRPORTARRIVAL = to_airport.AIRPORTID
INNER JOIN ROUTETABLE route ON FLIGHTTABLE.AIRPORTARRIVAL = route.TOAIRPORTID && FLIGHTTABLE.AIRPORTDEPARTURE = route.FROMAIRPORTID
WHERE $dateofdeparture_update $dateofarrival_update $airportofdeparture_update $airportofarrival_update $id_update$seats_update $status_update;";

$res = mysql_query($query, GetMyConnection() );
if (!mysql_num_rows($res))
{
if ($id)
{
$results = array('success' => false, 'error' => 'Este voo não foi encontrado');
} else {
$results = array('success' => false, 'error' => 'Nenhum voo foi encontrado');
}
}
else
{

while($row = mysql_fetch_array($res))
{
//echo $row;
$data[] = array(
'id' => $row['FLIGHTID'],
'status' => $row['FLIGHTSTATUS'],
'reason' => $row['REASON'],
'airplane' => array(
'id' => $row['AIRPLANEID'],
'name' => $row['NAME']
),
'departure' => $row['DATEOFDEPARTURE'],
'arrival' => $row['DATEOFARRIVAL'],
'fromairport' => $row['AIRPORTDEPARTURE'],
'fromairportname' => $row['NAMEOFAIRPORT'],
'toairport' => $row['AIRPORTARRIVAL'],
'toairportname' => $row['NAMEOFAIRPORT'],
'price' => $row['PRICE'],
'availableseats' => $row['AVAILABLESEATS'],
'price' => $row['PRICE'],
'photo' => $row['PHOTO'],
);
}

$results = array('success' => true, 'data' => $data);

尽管 'fromairportname''toairportname' 应该具有不同的值,但它们具有相同的值,因为 $row['NAMEOFAIRPORT'],具有相同的值。如何获取第二个内部联接的 $row['NAMEOFAIRPORT'] 以便它们显示实际的出发和到达数据?

谢谢

最佳答案

$query="SELECT FLIGHTTABLE.FLIGHTID, 
FLIGHTSTATUS,
REASON,
FLIGHTTABLE.AIRPLANEID,
DATEOFDEPARTURE,
DATEOFARRIVAL,
AIRPORTDEPARTURE,
from_airport.NAMEOFAIRPORT AS TONAMEOFAIRPORT,
AIRPORTARRIVAL,
to_airport.NAMEOFAIRPORT AS FROMNAMEOFAIRPORT,

将列重命名为 from_airport.NAMEOFAIRPORT AS TONAMEOFAIRPORT 解决了问题。

感谢大家的帮助

关于php - 如何访问同名的PHP表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26673758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com