heres the coding right now.
<?
$content=file("$form_data");
unset($content[1]);
$tabbed=implode("",preg_replace('%[ ]{2,}%s', "\t", $content));
preg_match_all("%(.*)\t(.*)\t(.*)\t(.*)%miU", $tabbed, $matches);
echo '<table border="1">
<tr>
<th>'.$matches[1][0].'</th>
<th>'.$matches[2][0].'</th>
<th>'.$matches[3][0].'</th>
</tr>';
for ($i=1; $i<count($matches[1]);$i++)
echo '<tr>
<td>'.$matches[1][$i].'</td>
<td>'.$matches[2][$i].'</td>
<td>'.$matches[3][$i].'</td>
</tr>';
echo '</table>';
?>
<?
$db=mysql_connect("localhost", "user","pass");
mysql_select_db("mflblin_madden",$db);
//getting the teams's names
$team1=$matches[2][0];
$team2=$matches[3][0];
//querying their ids
echo $sql="SELECT
team_id, team_name
FROM
team
WHERE
team_name IN ('".$team1."', '".$team2."')";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_assoc($result))
$teams[]=$row;
//order them correct
if ($teams[0]['team_name']!=$matches[2][0])
list($teams[0], $teams[1])=array($teams[1], $teams[0]);
//insert game
print_r($teams);
echo $sql='INSERT INTO game
SET team1='.$teams[0]['team_id'].', team2='.$teams[1]['team_id'];
mysql_query($sql) or die(mysql_error());
//retrieve game_id
$game=mysql_insert_id();
//insert data
for ($i=1; $i<count($matches[2]); $i++)
$data[]=$matches[2][$i];
echo $sql='INSERT INTO result
(game_id, team_id, points, benchscoring, fieldgoals, fieldgoalp, threepointfg, threepointfgp, freethrows, freethrowp, rebounds, offrebounds, defrebounds, blocks, steals, assists, turnovers, fouls)
VALUES ('.$game.', '.$teams[0]['team_id'].', '.implode(', ', $data).')';
// Set $points1 to number of points for Team 1
$points1 = $data[0];
unset($data);
//test output
echo '<hr />'.$sql.'<p />';
mysql_query($sql) or die(mysql_error());
//the same for team2
for ($i=1; $i<count($matches[3]); $i++)
$data[]=$matches[3][$i];
echo $sql='INSERT INTO result
(game_id, team_id, points, benchscoring, fieldgoals, fieldgoalp, threepointfg, threepointfgp, freethrows, freethrowp, rebounds, offrebounds, defrebounds, blocks, steals, assists, turnovers, fouls)
VALUES ('.$game.', '.$teams[1]['team_id'].', '.implode(', ', $data).')';
// Set $points2 to number of points for Team 2
$points2 = $data[0];
//test output
echo $sql.'<hr />';
mysql_query($sql) or die(mysql_error());
echo $points1. '<hr />';
echo $points2. '<hr />';
//assuming $points1 are points of $teams[0]['team_id']
if ($points1 > $points2) //team1 won
{
mysql_query('UPDATE team SET wins=wins+1 WHERE team_id='.$teams[0]['team_id']);
mysql_query('UPDATE team SET losses=losses+1 WHERE team_id='.$teams[1]['team_id']);
}
else //team2 won
{
mysql_query('UPDATE team SET wins=wins+1 WHERE team_id='.$teams[1]['team_id']);
mysql_query('UPDATE team SET losses=losses+1 WHERE team_id='.$teams[0]['team_id']);
}
?>
Now in the table result. There is 2 columns at end. opponent and score.
Now the opponent needs to be filled with the name of the team you faced. The score needs to be your opponents points scored.
All this is already put in the database but in seperate rows. So you can prob do a WHERE statement or something. The game log that is submitted is attached. Heres some more info
$teams[0]['team_id']); This =s the team name on left.
$teams[1]['team_id']; This =s the team name on right
Now you see where it says $points1 an 2 ?? well $points1=s the points from the team on the left. Points2 is the right.
But this only works because of where the values are set. The data is all unset after the first $points1
One other thing I think is possible. All the data is already submitted to table besides them 2 columns. The opponents team name is on the table but in a different row but with the same game_id so is his score.
The columns you prob would need to know are team_id, points
Another thing is the team name is not what is submitted to result table its the team_id