Johan
Johan

Reputation: 69

Multiple INNER JOIN not working

I can't get both INNER JOINS working. Data is being displayed when I only use the first INNER JOIN but there's nothing being displayed when I add the second INNER JOIN.

Here's the code I'm using where the url would be: website.com/matchdetails/season/match_id

     <?php
     $db = new PDO('mysql:host=db.xx.xx;dbname=xx','xx','xx'); 

     $sth = $db->prepare("
     SELECT *
     FROM 
         matchdetails AS md 
     INNER JOIN 
         players AS p
             ON 
             (p.player_id = md.player_id) 
     INNER JOIN
         matches AS m
             ON
             (m.match_id = md.match_id) 
              WHERE (CONCAT_WS('/', season, match_id)) = :season");
     $sth->execute(array(':season' => substr($_SERVER['PATH_INFO'], 1)));
     foreach($sth as $row) {?>
     <?php echo 'Name '. $row['name'] . '<br/>'; ?> 
     <?php echo 'Goals ', $row['goals'] . '<br/>'; ?> 
     <?php echo 'Assists ',$row['assists'] . '<br/>'; ?> 
     <?php echo 'VVO Score ',$row['vvo_score'] . '<br/>' . '<br/>'; ?> 
     <?php }?>

My database structure is:

Table matches

enter image description here

Table matchdetails

enter image description here

Table players

enter image description here

Upvotes: 1

Views: 1145

Answers (1)

Squall
Squall

Reputation: 4472

In ON (p.player_id = m.player_id), m is the table 'matches' and 'matches' has no column whose name is 'player_id'.

Upvotes: 2

Related Questions