亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP - 關聯表的爆炸結果查詢

PHP - 關聯表的爆炸結果查詢

PHP
慕娘9325324 2021-12-24 14:55:42
我的 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;


查看完整回答
反對 回復 2021-12-24
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號