Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-关联表的分解结果查询_Php_Mysql - Fatal编程技术网

PHP-关联表的分解结果查询

PHP-关联表的分解结果查询,php,mysql,Php,Mysql,我的sql数据库中有两个关联的表。一个是名为“机场”的机场列表,另一个是名为“机场概况”的航空公司列表。后者是我想重点关注的。我通过机场id行将航空公司与机场关联。i、 e身份证号码指的是机场。我当前的PDO查询是: if(isset($_GET['airport'])) { if ($_GET['airport'] == 1) { $airportQuery = "SELECT * FROM airport_profiles"; $airport = $db->prepa

我的sql数据库中有两个关联的表。一个是名为“机场”的机场列表,另一个是名为“机场概况”的航空公司列表。后者是我想重点关注的。我通过机场id行将航空公司与机场关联。i、 e身份证号码指的是机场。我当前的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\u id)
但这根本不起作用

如果我错了,请纠正我,但根据我的理解,为了将多家航空公司关联到一个机场,我需要添加一个爆炸“;”以使我的机场id的分号分隔。任何建议都将受到极大欢迎。
非常感谢。查询更改为以下内容:

    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;

很难说出你在问什么。通常,explode与数据库查询完全无关。你能把那些爆炸性的东西放在一边,解释一下你面临的实际问题吗。我对造成的混乱表示诚挚的歉意。简言之,我需要能够将多家航空公司关联到一个机场。在数据库方面,这意味着添加多个id,可以是逗号或分号分隔的id,然后依次提供我当前获得的多个结果。根据我的理解,这取决于查询。您只需向airline表中添加更多行即可。由于机场id字段,它们都已与机场关联。不需要其他任何东西你是说为每个航空公司增加一行吗?因为那样会有很多结果。这样做的目的是创建一个带有机场填充列表的“选择”下拉列表。当一个机场被选中时,它会得到为该机场服务的航空公司。我不理解你的问题。你不是已经为每一家航空公司吵架了吗?有一个表airlines,用来存储关于航空公司的信息,每一个都在不同的行中。所以我真的很困惑。