Hope someone can help me out with this one.
Table 1 contains 58 players.
Table 2 contains 68 teams.
Table 3 contains fixtures based on Table 1 and Table 2.
What I have is a form that outputs each record from Table 1 as text and then a combo box with all the teams from Table 2. So for every record in Table 1, there is a combo box with all the teams listed in it on the webpage.
The user looks at each name and then chooses a team from the combo box. What I need to do is take all 58 names and add the team that was chosen from the combo box to Table 3.
I'm assuming I need some kind of an array to read in all the chosen teams from the combo box for each name but I have no idea how to go about this or what the SQL query would look like to do this.
Obviously as it stands, when Submit is pressed it will only read in the last entry, and not all 58. I need this to be dynamic so that no matter how many records there are in Table 1, it will add however many.
Hope this makes sense and any help appreciated.
Table 1 contains 58 players.
Table 2 contains 68 teams.
Table 3 contains fixtures based on Table 1 and Table 2.
What I have is a form that outputs each record from Table 1 as text and then a combo box with all the teams from Table 2. So for every record in Table 1, there is a combo box with all the teams listed in it on the webpage.
The user looks at each name and then chooses a team from the combo box. What I need to do is take all 58 names and add the team that was chosen from the combo box to Table 3.
I'm assuming I need some kind of an array to read in all the chosen teams from the combo box for each name but I have no idea how to go about this or what the SQL query would look like to do this.
Code:
$submit = $_POST['submit'];
$fixture_draw_id = $_POST['f_fixture_draw_id'];
$fixture_team_id = $_POST['f_fixture_team_id'];
$fixture_player_id = $_POST['f_fixture_player_id'];
if ( $submit )
{
$query = mysql_query("INSERT INTO $fixtures ( fixture_draw_id, fixture_team_id, fixture_player_id ) values ( '$fixture_draw_id', '$fixture_team_id', '$fixture_player_id' )");
echo "Added.<br>";
echo "<a href='index.php?action=addfixture'>Add another</a><br><br><a href='index.php'>Back to Main Page</a>";
}
else
{
echo "<form method='post' action=''>\n";
echo "<table border='0' cellspacing='1' cellpadding='1' summary='' class='black'>\n";
$result = mysql_query("SELECT * FROM $draws ORDER BY draw_id DESC LIMIT 0,1");
while($r=mysql_fetch_array($result))
{
$draw_id=$r["draw_id"];
$draw_date=$r["draw_date"];
}
echo "<tr>\n<td>Draw: </td>\n<td><input type='hidden' name='f_fixture_draw_id' value='$draw_id'>$draw_date</td>\n</tr>\n";
echo "<tr>\n<td> </td>\n</tr>\n";
$result = mysql_query("SELECT * FROM $players ORDER BY player_name ASC");
while($r=mysql_fetch_array($result))
{
$player_id = $r["player_id"];
$player_name = $r["player_name"];
echo "<tr>\n<td>$player_name</td>\n<td><select name='f_fixture_team_id'>";
echo "<option value='-'>-- Choose Team --</option>";
$result1 = mysql_query("SELECT * FROM $teams ORDER BY team_name ASC");
while($r1=mysql_fetch_array($result1))
{
$team_id = $r1["team_id"];
$team_name = $r1["team_name"];
echo "<option value='$team_id'>$team_name</option>";
}
echo "</select></td>\n</tr>\n";
}
echo "<tr>\n<td><br><input type='submit' name='submit' value='Submit'><br><br><a href='index.php'>Back to Main Page</a></td>\n</tr>\n";
echo "</table>\n</form>\n";
}
Obviously as it stands, when Submit is pressed it will only read in the last entry, and not all 58. I need this to be dynamic so that no matter how many records there are in Table 1, it will add however many.
Hope this makes sense and any help appreciated.