stfc_boy
07-01-2007, 07:40 PM
Hi All,
Wondering if someone could help me with my last part of my update script which records players an goalscorers in a five-aside football match Here's my database:
http://www.sloughtownfc.net/statistics.jpg
and I want to do two things:
1) Output the values into my form (code posted below) where match_id=1 (via get)
2) Update these values upon submit
Now, i've tried to do this below, but got very stuck writing this update script.
Can anyone please help?
Thanks
<?php
if(isset($_POST['Submit']))
{
$match_id = $_GET['match_id'];
if(isset($_GET['match_id']))
{
foreach($_REQUEST['r'] as $position => $row)
{
$x = implode("', '",$row);
$position = $x[0];
$name = $x[1];
$result = mysql_query("UPDATE player_stats SET position='$position',name='$name', goals='$goals', match_id='$match_id' WHERE match_id=".$_GET['match_id']);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Player stats</title>
</head>
<body>
<form name="statistics" method="post" action="">
<table width="100%">
<?
$result = mysql_query("SELECT * FROM player_stats WHERE match_id=".$_GET['match_id']);
$numresults = mysql_num_rows($result);
for ($i = 0; $i < $numresults; $i++)
{
$player = mysql_fetch_array($result);
$name = $row['name'];
$goals = $row['goals'];
$match_id = $row['match_id'];
echo'<tr>
<td width="33%">Player</td>
<td width="33%">Name</td>
<td width="33%">Goals</td>
</tr>
<tr>
<td width="33%">Goalkeeper:</td>
<td width="33%"><input name="r[goalkeeper][name]" type="text" value="'. $row['name'] .'" size="36" /></td>
<td width="33%"><input name="r[goalkeeper][goals]" type="text" value="'. $row['goals'] .'" size="36" /></td>
</tr>
<tr>
<td width="33%">Player Two</td>
<td width="33%"><input name="r[player_two][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_two][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Three</td>
<td width="33%"><input name="r[player_three][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_three][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Four</td>
<td width="33%"><input name="r[player_four][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_four][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Five</td>
<td width="33%"><input name="r[player_five][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_five][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>';
}
?>
</table>
<input type="submit" name="Submit" value="Submit"/>
</form>
</body>
</html>
Wondering if someone could help me with my last part of my update script which records players an goalscorers in a five-aside football match Here's my database:
http://www.sloughtownfc.net/statistics.jpg
and I want to do two things:
1) Output the values into my form (code posted below) where match_id=1 (via get)
2) Update these values upon submit
Now, i've tried to do this below, but got very stuck writing this update script.
Can anyone please help?
Thanks
<?php
if(isset($_POST['Submit']))
{
$match_id = $_GET['match_id'];
if(isset($_GET['match_id']))
{
foreach($_REQUEST['r'] as $position => $row)
{
$x = implode("', '",$row);
$position = $x[0];
$name = $x[1];
$result = mysql_query("UPDATE player_stats SET position='$position',name='$name', goals='$goals', match_id='$match_id' WHERE match_id=".$_GET['match_id']);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Player stats</title>
</head>
<body>
<form name="statistics" method="post" action="">
<table width="100%">
<?
$result = mysql_query("SELECT * FROM player_stats WHERE match_id=".$_GET['match_id']);
$numresults = mysql_num_rows($result);
for ($i = 0; $i < $numresults; $i++)
{
$player = mysql_fetch_array($result);
$name = $row['name'];
$goals = $row['goals'];
$match_id = $row['match_id'];
echo'<tr>
<td width="33%">Player</td>
<td width="33%">Name</td>
<td width="33%">Goals</td>
</tr>
<tr>
<td width="33%">Goalkeeper:</td>
<td width="33%"><input name="r[goalkeeper][name]" type="text" value="'. $row['name'] .'" size="36" /></td>
<td width="33%"><input name="r[goalkeeper][goals]" type="text" value="'. $row['goals'] .'" size="36" /></td>
</tr>
<tr>
<td width="33%">Player Two</td>
<td width="33%"><input name="r[player_two][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_two][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Three</td>
<td width="33%"><input name="r[player_three][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_three][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Four</td>
<td width="33%"><input name="r[player_four][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_four][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>
<tr>
<td width="33%">Player Five</td>
<td width="33%"><input name="r[player_five][name]" type="text" value="'. $row['name'] .' " size="36" /></td>
<td width="33%"><input name="r[player_five][goals]" type="text" value="'. $row['goals'] .' " size="36" /></td>
</tr>';
}
?>
</table>
<input type="submit" name="Submit" value="Submit"/>
</form>
</body>
</html>