我的 sql 數據庫中有兩個關聯的表。一個是名為“airports”的機場列表,另一個是名為“airport_profiles”的航空公司列表。后者是我想關注的。我通過 airport_id 行將航空公司與機場相關聯。即身份證號碼參考機場。我當前的 PDO 查詢是:if(isset($_GET['airport'])) {if ($_GET['airport'] == 1) { $airportQuery = "SELECT * FROM airport_profiles"; $airport = $db->prepare($airportQuery); $airport->execute();}else { $airportQuery = "SELECT * FROM airport_profiles WHERE airport_id = :airport_id"; $airport = $db->prepare($airportQuery); $airport->execute(['airport_id' => $_GET['airport']]);} $selectedAirport = $airport->fetchAll(); foreach ($selectedAirport as $profile) { if ($profile['id'] == 1) continue;我試過插入 $profile = explode(';', $airport_id); 但這根本不起作用。如果我錯了,請糾正我,但根據我的理解,為了將不止一家航空公司與一個機場相關聯,我需要添加一個爆炸“;” 到查詢,以便我的 airport_id 的分號分隔。任何建議都將受到極大歡迎。提前謝謝了。
1 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
查詢更改為以下內容:
if(isset($_GET['airport'])) {
if ($_GET['airport'] == 1) {
$airportQuery = "SELECT * FROM airport_profiles GROUP BY airline_name";
$airport = $db->prepare($airportQuery);
$airport->execute();
}
else {
$airportQuery = "SELECT * FROM airport_profiles WHERE airport_id = :airport_id";
$airport = $db->prepare($airportQuery);
$airport->execute(['airport_id' => $_GET['airport']]);
}
$selectedAirport = $airport->fetchAll();
foreach ($selectedAirport as $profile) {
if ($profile['id'] == 1) continue;
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消