在请求sql中获取具有相同名称的行

hrirmatl  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(292)

我不能正确地提取同名的两行。那是我的table“装备”

这就是我的“对抗”

这是我的密码

$semaine = $item['semaine'];
   $query = " SELECT *
    FROM confrontations
    LEFT OUTER JOIN equipes
    ON confrontations.id_equipe1 = equipes.id_equipe
    WHERE semaine = :semaine
    UNION
    SELECT *
    FROM confrontations
    LEFT OUTER JOIN equipes
    ON confrontations.id_equipe2 = equipes.id_equipe   
    WHERE semaine = :semaine2";
    $check = $pdo->prepare($query);
    $check->bindParam(':semaine', $semaine, PDO::PARAM_INT);
    $check->bindParam(':semaine2', $semaine, PDO::PARAM_INT);
    $check->execute();

我想打印像:博洛涅-热那亚那不勒斯-希腊维隆国际米兰-拉齐奥。。。
但如果我这么做,我会得到:

> $rows = $check->fetchAll(PDO::FETCH_ASSOC);
>         foreach ($rows as $row){
>             echo $row['libelle_equipe'] . "<br>" . $row['libelle_equipe'];
>         }


如何获得和打印正确的对符?

krcsximq

krcsximq1#

你应该参加两次会议。。

SELECT a.*, e1.libelle_equipe equipe1, e2.libelle_equipe equipe2
    FROM confrontations a
    INNER JOIN equipes e1 ON a.id_equipe1 = e1.id_equipe
    INNER JOIN equipes e2 ON a.id_equipe2 = e2.id_equipe
    WHERE a.semaine = :semaine

..

foreach ($rows as $row){
         echo $row['equipe1'] . " - " . $row['equipe2'] .  "<br>";
    }

显然亚特兰大赢得了所有的比赛。。

相关问题