PDA

View Full Version : Help me create a function


rbpd5015
11-23-2005, 07:35 AM
This might be more of a mysql question but I will ask it here also.

I am working on a stat outputer for american football stats. I load a file each week of the 17 weeks of the NFL season each week the file has total stats not ind week stats. I want to create Ind stats by subtracting the total stats from the previous weeks total stats. SO I got to tables one one has just total stats and one will have week by week stats.

I got 2 tables

MYSQL_PASSING
MYSQL_GBGPASSING

MYSQL_PASSING
has the following fields
"(`id`, `year`, cmp, att, yds, sack, td, `int`, `long`) "

MYSQL_GBGPASSING (GBG is game by game)
has the following fields
"(`id`, `year`, wk, cmp, att, yds, sack, td, `int`, `long`) "

What I am trying to do is basically

take MYSQL_GBGPASSING get built from breaking down MYSQL passing into indivdual games.

I also believe I set the table MYSQL_GBGPASSING wrong. It needs to be able to have duplicate ID YEAR and WEEK but not duplicate of all three together. See you can have ID #344 17 times in the WK FIELD. but you can only have 1 ID 355 WK 1 YEAR 2005. here is what I got so far.

$gbgpassing = "CREATE TABLE `" . MYSQL_GBGPASSING . "` ("
."`id` int(11) NOT NULL default '0',"
."`year` year(4) NOT NULL default '0000',"
."`wk` int(11) NOT NULL default '0',"
."`cmp` int(11) NOT NULL default '0',"
."`att` int(11) NOT NULL default '0',"
."`yds` int(11) NOT NULL default '0',"
."`sack` int(11) NOT NULL default '0',"
."`td` int(11) NOT NULL default '0',"
."`int` int(11) NOT NULL default '0',"
."`long` int(11) NOT NULL default '0',"
."PRIMARY KEY (`id`,`year`),"
."KEY `id` (`id`),"
."KEY `year` (`year`)"
.") TYPE=MyISAM";


below is what I got please tell me what you think I am doing wrong.



function sql_insertPlayerGbgPassingStats($id, $year, $table)
{
$db_table = MYSQL_GBGPASSING;

if (!sql_emptyStats($db_table, $id, $year))
return errorPrint("The call to sql_emptyStats() in sql_insertPlayerGbgPassingStats($id, $year, $table) failed");

$cmp = $table[2]; $att = $table[3]; $yds = $table[4]; $sack = $table[7]; $td = $table[8];
$int = $table[9]; $long = $table[10]; $wk = 3;

$query = "INSERT INTO $db_table "
."(`id`, `year`, wk, cmp, att, yds, sack, td, `int`, `long`) "
."VALUES ($id, $year, $wk, $cmp, $att, $yds, $sack, $td, $int, $long)";
$result = @mysql_query($query);
if ($result == false)
return errorPrint("The following query in sql_insertPlayerGbgPassingStats($id, $year, $table); failed: <p><tt>$query</tt></p>");

return true;
}