0

how can I display the name of both teams (lteam and vteam)? Query works now... This is a screenshot of the SQL results:enter image description here http://prntscr.com/f9mkqh

$sql = "
SELECT * 
  FROM fixtures 
  LEFT 
  JOIN teams AS a 
    ON fixtures.lteam = a.id
  LEFT 
  JOIN teams AS b 
    ON fixtures.vteam = b.id
 WHERE date_ko = '2017-05-19'
";
echo '<table>';
echo '<tbody>';

foreach($pdo->query($sql) as $row)
    {
    echo '<tr>';
    echo '<td>' . $row['lteam'] . '</td>';
    echo '<td>' . $row['name'] . '</td>';
    echo '<td>-</td>';
    echo '<td>' . $row['vteam'] . '</td>';
    echo '<td>' . $row['b.name'] . '</td>';
    echo '</tr>';
    }

echo '</tbody>';
echo '</table>';

Thanks!

1 Answer 1

1

The SQL result header is somewhat confusing, and as I don't know fully how the tables and schemas are structured, I have to assume you are having trouble with getting the name attribute from the teams table, as this is joined in two times.

You will need to select the columns explicitly and naming them something else for this to work. For example:

SELECT *, `a`.`name` as `team1name`, `b`.`name` as `team2name` FROM fixtures [...]

Now you should be able to grab the team names under their assigned aliases.

Sign up to request clarification or add additional context in comments.

1 Comment

You are the boss! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.