I've looked up and down here but couldn't find anything that works. I'm trying to join two tables and output team1id and team2id from the resulting table.
//Query
$sql = "SELECT match.*, matchrelations.match_id, matchrelations.poolname
FROM match JOIN matchrelations
ON match.id=matchrelations.match_id
WHERE matchrelations.poolname='$poolname'";
//Debugging
if (!$check1_res) {
printf("Error: %s
", mysqli_error($link));
exit();
}
//Query database
$result = mysqli_query($link,$sql);
//Echo
while($row = mysqli_fetch_assoc($result))
{
$team1 = $row['match.team1id'];
$team2 = $row['match.team2id'];
echo "$team1 VS $team2";
echo "<br>";
}
The error is being thrown in the sql statement, and produces error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, matchrelations.match_id, matchrelations.poolname FROM match JOIN matchrela' at line 1
I'm not sure what I'm doing wrong..
Looks like match is a reserved word in mysql. Try this:
SELECT `match`.*, matchrelations.match_id, matchrelations.poolname
FROM `match` JOIN matchrelations
ON `match`.id=matchrelations.match_id
WHERE matchrelations.poolname='$poolname';
Try
$sql = "SELECT m.*, mr.match_id, mr.poolname
FROM `match` m JOIN `matchrelations` mr
ON (m.id=mr.match_id)
WHERE mr.poolname='$poolname'";