I'm back, with a similar problem :queasy:
I'm in the situation where I can now successfully add fixtures to the database, but I am stuck on the stage of displaying the fixtures.
I got to the point where I could pull the fixtures from the database to display them for a user, but then realised that input boxes need to be associated with the fixtures (in order for users to predict the score for each fixture). I tried creating a for loop to make each input box have a unique id, which has worked, but now the fixtures wont display properly.
The basic problem I'm having is that the loop is displaying only the first fixture from the database, but multiple times.
The code has become a bit long, but here goes...
<?php
$sql = "SELECT team_1, team_2, fixture_date, date_added, gameweek, active FROM fixtures";
$result = mysql_query($sql) or die(mysql_error());
while ($i = mysql_fetch_array($result)) {
$team1 = $i['team_1'];
$getTeamName = "SELECT team_name, league_image
FROM teams, fixtures
WHERE teams.id = fixtures.team_1
AND teams.id = $team1";
$teamName = mysql_query($getTeamName) or die(mysql_error());
while ($getTeam = mysql_fetch_array($teamName)) {
$team1Name = $getTeam['team_name'];
$image1 = $getTeam['league_image'];
}
$team2 = $i['team_2'];
$getTeamName = "SELECT team_name, league_image
FROM teams, fixtures
WHERE teams.id = fixtures.team_2
AND teams.id = $team2";
$teamName = mysql_query($getTeamName) or die(mysql_error());
while ($getTeam = mysql_fetch_array($teamName)) {
$team2Name = $getTeam['team_name'];
$image2 = $getTeam['league_image'];
}
$fixtureDate = $i['fixture_date'];
$dateAdded = $i['date_added'];
$gameweek = $i['gameweek'];
$active = $i['active'];
$sql = "SELECT num_fixtures FROM fixture_details";
$result = mysql_query($sql) or die(mysql_error());
while ($i = mysql_fetch_array($result)) {
$num = $i['num_fixtures'];
}
for($i = 1; $i <= $num; $i++){
?>
<tr>
<th style="width: 160px"><p align="right"><?php echo $team1Name; ?></p></th>
<td><img src="images/badge_icons/<?php echo $image1; ?>"></td>
<td><input type="text" id="Fixture<?php echo $i; ?>Team1" name="date" style="width: 20px;" maxlength="10" /></td>
<td><p>v</p></td>
<td><input type="text" id="Fixture<?php echo $i; ?>Team2" name="date" style="width: 20px;" maxlength="10" /></td>
<td><img src="images/badge_icons/<?php echo $image2; ?>"></td>
<th style="width: 160px"><p align="left"><?php echo $team2Name; ?></p></th>
</tr>
<?php } } ?>
The input id is unique with this code, but only the first fixture from the database is displayed (but multiple times, depending on how many fixtures are present in the database).
Thanks very much for all the help so far, and I appreciate you taking time to look at this next problem.