Hi, I have a fantasy football website, and on a user account page I want to display fixtures that are coming up that include teams that the current user has chosen. My test_teams table stores all the team names and their teamid. The test_selections table is where each users team selections are stored, it has two columns, userid and teamid. The test_fixtures table has two columns, hometeam and awayteam, these two cloumns hold the teamid of the teams that are playing.
I am really struggling writing the code. I have got the code below that seems to be selecting the users teams correctly but then is matching them up with every possible combination from test_teams table and is not picking the correct fixtures up from the test_fixtures table. Any help would be very much appreciated. Thanks in advance.
I am really struggling writing the code. I have got the code below that seems to be selecting the users teams correctly but then is matching them up with every possible combination from test_teams table and is not picking the correct fixtures up from the test_fixtures table. Any help would be very much appreciated. Thanks in advance.
PHP Code:
<table width="635" border="0">
<?php
$query = "SELECT tf.competition, tf.date, tth.team as hometeam, tta.team as awayteam
FROM test_selections ts
LEFT JOIN (test_fixtures tf, test_teams tth, test_teams tta)
ON (ts.userid = '{$_SESSION['userid']}' AND
(tf.hometeam = ts.teamid AND tth.teamid = tf.hometeam) OR
(tf.awayteam = ts.teamid AND tta.teamid = tf.awayteam))";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<td width="85" class="fixtures_date"><?php echo $row['date']; ?></td>
<td width="30" class="fixtures_comp"><?php echo $row['competition']; ?></td>
<td width="135" class="fixtures_home_teams"><?php echo $row['hometeam']; ?></td>
<td width="25" class="fixtures_center">v</td>
<td width="135" class="fixtures_away_teams"><?php echo $row['awayteam']; ?></td>
</tr>
<?php
}
?>
</table>
Comment