Hey,
I'm making a basic football simulator for a play by mail game where users submit their teamsheets through the post. I'm automating the system so that I select the teams on a website which then simulates the match for me and returns a result.
The home/away teams are presented in a table, taken from a MySQL database which checkboxes next to each player to select them to play in that match here:
$p=mysql_query("SELECT * FROM fixtures WHERE fixtureid='{$_GET['match']}' LIMIT 1", $c);
$pa=mysql_fetch_array($p);
print "<b><center><font size=+1>{$pa['homename']} v {$pa['awayname']}</font><br />
Division {$pa['tournament']} fixture | Turn {$pa['turn']}<br /><br />";
if ($pa['played'] > 0)
{
print "<b>This match has already been simulated. If you have entered the incorrect team or are unhappy with the result then please continue to select the squad.<br /><br /></b>";
}
$ht=mysql_query("SELECT * FROM players WHERE teamcode={$pa['hometeam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
$at=mysql_query("SELECT * FROM players WHERE teamcode={$pa['awayteam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
print "<form action='playmatch.php?stage=B&match=". $_GET['match']. "' method=post>
<div style='position: absolute; left: 200px; top: 80px; width: 300px; padding: 1em;'>";
print "<font size=-1>
<table border=0>";
while ($h=mysql_fetch_array($ht))
{
print "<tr><td width=2%><input type='checkbox' value='" . $h['playerid'] ."' name='home[]'></td><td>
{$h['surname']}</td>
<td>{$h['pos1']}";
- $p=mysql_query("SELECT * FROM fixtures WHERE fixtureid='{$_GET['match']}' LIMIT 1", $c);
- $pa=mysql_fetch_array($p);
- print "<b><center><font size=+1>{$pa['homename']} v {$pa['awayname']}</font><br />
- Division {$pa['tournament']} fixture | Turn {$pa['turn']}<br /><br />";
- if ($pa['played'] > 0)
- {
- print "<b>This match has already been simulated. If you have entered the incorrect team or are unhappy with the result then please continue to select the squad.<br /><br /></b>";
- }
- $ht=mysql_query("SELECT * FROM players WHERE teamcode={$pa['hometeam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
- $at=mysql_query("SELECT * FROM players WHERE teamcode={$pa['awayteam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
-
- print "<form action='playmatch.php?stage=B&match=". $_GET['match']. "' method=post>
- <div style='position: absolute; left: 200px; top: 80px; width: 300px; padding: 1em;'>";
-
- print "<font size=-1>
- <table border=0>";
- while ($h=mysql_fetch_array($ht))
- {
-
- print "<tr><td width=2%><input type='checkbox' value='" . $h['playerid'] ."' name='home[]'></td><td>
- {$h['surname']}</td>
- <td>{$h['pos1']}";
-
The form then continues and it is the same for the away team except the name for the checkbox is 'away[]'.
Where I am having trouble is I do not know how to interpret the returned data for the form on the next page.
I need to select every player (who has been selected) from the database using the player's unique id number from the value of:
value='" . $h['playerid'] ."'
I have tried various foreach/while statements but they do not seem to return anything. At the moment I have
print "{$_POST['home']}";
- print "{$_POST['home']}";
-
On the return screen which prints the word 'Array'. Therefore I know the information is being sent through the form as an associative array, but I do not know how to access and use the values returned.
Any help is greatly appreciated, Jake
PS, I know my php and sql is slightly outdated/strange, basically because I learnt it all from MCCode a few years back, but still, it does the job.