<?
$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).')';
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).')';
//test output
echo $sql.'<hr />';
mysql_query($sql) or die(mysql_error());
?>
Now ive been looking at this for awhile. Trying to add a query where it updates the team table Column wins and losses. It has to add to the Column wins or losses for whatever team had the highest and lowest points total. The problem is its not working. Heres what I came up with
//test output
echo $sql.'<hr />';
mysql_query($sql) or die(mysql_error());
$team_sql = "SELECT wins,losses,team_id FROM team WHERE team_id IN ($team_id1, $team_id2)";
$team_result = mysql_query($team_sql);
while($team_row = mysql_fetch_assoc($team_result))
{
list($wins,$losses,$id) = $team_row;
if ($points1 > $points2)
{
if($id = $team_id1)
{
$wins++;
$result = mysql_query("UPDATE team SET wins=$wins WHERE team_id=$id");
}
else
{
$losses++;
$result = mysql_query("UPDATE team SET losses=$losses WHERE team_id=$id");
}
}
else
{
if($id = $team_id1)
{
$losses++;
$result = mysql_query("UPDATE team SET losses=$losses WHERE team_id=$id");
}
else
{
$wins++;
$result = mysql_query("UPDATE team SET wins=$wins WHERE team_id=$id");
}
}
}
?>
I get a mysql_fetch error. What I need it to do is make the column 1 number higher then it is atm Column name is wins, losses