Ok. Mmm. Seems like a lot of logic needs to be pulled apart and defined.
Here is how I do things. Break down problems into small chunks! Lets say you have a single players data. You just need to create a function to insert that data into a table. One might write:
function SQLInsertPlayerResult($statsid, $playerid, $gameid, $season, $events)
{
return "INSERT INTO table
(statsid,playerid,gameid,season," . implode(",", array_keys($events)) .")
VALUES($statsid,$playerid,$gameid,$season," .
implode(",", $events) . ")";
}
And then to use this function we call it with:
echo SQLInsertPlayerResult(10, 20, 30, 40,
array(
event1 => 1,
event2 => 2,
event3 => 3,
event4 => 4));
The results of this function is:
INSERT INTO table (statsid,playerid,gameid,season,event1,event2,event3,event4) VALUES(10,20,30,40,1,2,3,4)
Now that is all valid code. We have a simple function that generates SQL with will insert players data into a database. Your next question is then, how do you extract a players data from your internal array:
Well code like this will extract the event results for a given player:
$database[event15][player1] = "50 25";
$database[event15][player4] = "30 35";
$database[event17][player1] = "1";
$database[event16][player4] = "1";
$pid = "player1";
foreach ($database as $eid => $event)
{
if ($event[$pid]) $result[$eid] = $event[$pid];
}
print_r($result);
But, you might not know all the players, in which case you need to write a function that will build up a list of all players within your array.
So, we have 3 functions:
1) A function to get an array of all players within the array
2) A function to get all event results for a given player
3) A function to convert a players details and event results to a SQL INSERT statement.
You combine the 3 functions together, and bingo, you have your requirements.
Sing out if Im completely off the mark