Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 01-30-2008, 06:42 AM   #1
gottimd
Dearly Missed
(9/25/77-12/23/08)
 
Join Date: Nov 2003
Location: DC Suburbs
Php Help

So I am using gstelmacks interrogator to extract game data and upload to an online DB to run scripts off of. I have one that has every year as an option, and the last option is "Career", which should select from table "statsALL". For some reason, when I select it, defaults back to year 1 and only sums that year.

The code I have is:
Quote:
$year=$_POST['year']; // this picks up any change of year
$selplayers=$_POST['selplayers']; // this picks up the rookies or all players selection

$yearx=$year;

if(!isset($year)){$year='s.year = 2014';$table='stats2014';}
elseif($year=='2014'){$year = 's.year = 2014';$table='stats2014';}
elseif($year=='2013'){$year = 's.year = 2013';$table='stats2013';}
elseif($year=='2012'){$year = 's.year = 2012';$table='stats2012';}
elseif($year=='2011'){$year = 's.year = 2011';$table='stats2011';}
elseif($year=='2010'){$year = 's.year = 2010';$table='stats2010';}
elseif($year=='2009'){$year = 's.year = 2009';$table='stats2009';}
elseif($year=='2008'){$year = 's.year = 2008';$table='stats2008';}
elseif($year=='2007'){$year = 's.year = 2007';$table='stats2007';}
elseif($year=='2006'){$year = 's.year = 2006';$table='stats2006';}
elseif($year=='2005'){$year = 's.year = 2005';$table='stats2005';}
elseif($year=='2004'){$year = 's.year = 2004';$table='stats2004';}
elseif($year=='Career'){$year = 's.year > 2003';$table='statsALL';}


// passing yards
// this is the query for the passing yards
$qrystr = "SELECT ph.playerid, ph.firstname, ph.lastname, t.teamid, s.year, SUM(s.passyards) as stat
FROM (Historical_Player ph LEFT JOIN Active_Player pa ON pa.playerid=ph.playerid)
LEFT JOIN teams t ON pa.team=t.TeamID, $table s
WHERE ph.playerid=s.playerid
AND $year
$isRookie
AND s.week<23
GROUP BY ph.playerid, ph.firstname, ph.lastname, t.teamabbr, s.year
ORDER BY stat DESC
LIMIT $limit;";

Is it because the Group By last paramater is s.year? If it is, how can I write it to say if "Career" is selected, not to group it by that?
__________________
NAFL New Orleans Saints GM/Co-Commish
MP Career Record: 114-85
NAFL Super Bowl XI Champs
In memory of Gavin Anthony: 7/22/08-7/26/08


Last edited by gottimd : 01-30-2008 at 06:48 AM.
gottimd is offline   Reply With Quote
Old 01-30-2008, 02:36 PM   #2
3ric
College Starter
 
Join Date: Dec 2000
Location: Sweden
I'd try to limit those Group By parameters, only PlayerID and Year would suffice I think.

When Career is selected, you could get another Group By line by including an if statement and appending the new line to the string, like:
if ($career) {
$qrystr = $qrystr + "GROUP BY ph.PlayerID";
} else {
$qrystr = $qrystr + "GROUP BY ph.PlayerID, s.Year";
}
$qrystr = $qrystr + " ORDER BY stat DESC LIMIT $limit;";
__________________
San Diego Chargers (HFL) - Lappland Reindeers (WOOF) - Gothenburg Giants (IHOF)
Indiana: A TCY VC - year 2044 - the longest running dynasty ever on FOFC!
3ric is offline   Reply With Quote
Old 01-30-2008, 04:38 PM   #3
gottimd
Dearly Missed
(9/25/77-12/23/08)
 
Join Date: Nov 2003
Location: DC Suburbs
Quote:
Originally Posted by 3ric View Post
I'd try to limit those Group By parameters, only PlayerID and Year would suffice I think.

When Career is selected, you could get another Group By line by including an if statement and appending the new line to the string, like:
if ($career) {
$qrystr = $qrystr + "GROUP BY ph.PlayerID";
} else {
$qrystr = $qrystr + "GROUP BY ph.PlayerID, s.Year";
}
$qrystr = $qrystr + " ORDER BY stat DESC LIMIT $limit;";

Thanks 3ric!

Unfortunately the report is set up based on those paramaters so I do need all of those Group By's.

so you mean adding what you have into the following:
$qry = select_query2($qrystr);
// i use foreach as an easy way to display each row, you can use while as well
$rank=1;
foreach ($qry as $line){
$pid = $line[0];
$fname = $line[1];
$lname = $line[2];
$tid = $line[3];
$year = $line[4];
$stat = $line[5];

$initial=substr($fname,0,1);


http://www.naflsim.com/webpages/leaders.php
*takes a while to load
__________________
NAFL New Orleans Saints GM/Co-Commish
MP Career Record: 114-85
NAFL Super Bowl XI Champs
In memory of Gavin Anthony: 7/22/08-7/26/08
gottimd is offline   Reply With Quote
Old 01-31-2008, 06:10 AM   #4
Bonegavel
Awaiting Further Instructions...
 
Join Date: Nov 2001
Location: Macungie, PA
I think he meant that you should alter the group by based on $year being 'Career' or not.

something like this? (I like breaking apart my query into chunks so I apologize about my string formatting. Helps me figure out what is what.)

----------------------------------------------

Code:
if($year=='Career') { $GroupBy = "group by ph.playerid, ph.firstname, ph.lastname, t.teamabbr "; } else { $GroupBy = "group by ph.playerid, ph.firstname, ph.lastname, t.teamabbr, s.year "; } $qrystr = "SELECT ph.playerid, ph.firstname, ph.lastname, t.teamid, " ."s.year, SUM(s.passyards) as stat " ."FROM (Historical_Player ph LEFT JOIN Active_Player pa ON pa.playerid=ph.playerid) " ."LEFT JOIN teams t ON pa.team=t.TeamID, $table s " ."WHERE (ph.playerid=s.playerid AND $year $isRookie) " ."AND s.week<23 " ."$GroupBy " ."ORDER BY stat DESC " ."LIMIT $limit";
__________________


Bonegavel is offline   Reply With Quote
Old 01-31-2008, 06:23 AM   #5
marcmoustache
H.S. Freshman Team
 
Join Date: Jun 2005
Yep, sorry gottimd, my dodgy code, what bonegavel said will work
marcmoustache is offline   Reply With Quote
Old 01-31-2008, 06:32 AM   #6
gottimd
Dearly Missed
(9/25/77-12/23/08)
 
Join Date: Nov 2003
Location: DC Suburbs
Thanks guys...so I can just add it to this section?

// end of funtions

$year=$_POST['year']; // this picks up any change of year
$selplayers=$_POST['selplayers']; // this picks up the rookies or all players selection

$yearx=$year;

if(!isset($year)){$year='s.year = 2014';$table='stats2014';}
elseif($year=='2014'){$year = 's.year = 2014';$table='stats2014';}
elseif($year=='2013'){$year = 's.year = 2013';$table='stats2013';}
elseif($year=='2012'){$year = 's.year = 2012';$table='stats2012';}
elseif($year=='2011'){$year = 's.year = 2011';$table='stats2011';}
elseif($year=='2010'){$year = 's.year = 2010';$table='stats2010';}
elseif($year=='2009'){$year = 's.year = 2009';$table='stats2009';}
elseif($year=='2008'){$year = 's.year = 2008';$table='stats2008';}
elseif($year=='2007'){$year = 's.year = 2007';$table='stats2007';}
elseif($year=='2006'){$year = 's.year = 2006';$table='stats2006';}
elseif($year=='2005'){$year = 's.year = 2005';$table='stats2005';}
elseif($year=='2004'){$year = 's.year = 2004';$table='stats2004';}
elseif($year=='Career'){$year = 's.year > 2003';$table='statsALL';}

if($year=='Career'){$GroupBy = "group by ph.playerid, ph.firstname, ph.lastname, t.teamabbr ";}
else{$GroupBy = "group by ph.playerid, ph.firstname, ph.lastname, t.teamabbr, s.year ";}

And then change the group by in each statement to say $GroupBy, correct?
__________________
NAFL New Orleans Saints GM/Co-Commish
MP Career Record: 114-85
NAFL Super Bowl XI Champs
In memory of Gavin Anthony: 7/22/08-7/26/08
gottimd is offline   Reply With Quote
Old 01-31-2008, 06:38 AM   #7
marcmoustache
H.S. Freshman Team
 
Join Date: Jun 2005
yep
marcmoustache is offline   Reply With Quote
Old 01-31-2008, 08:56 AM   #8
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
PHP doesn't let you write that block like:

if(!isset($year)){$year='s.year = 2014';$table='stats2014';}
elseif($year=='Career'){$year = 's.year > 2003';$table='statsALL';}
else{$year = 's.year = '+$year;$table='stats'+$year;}

?
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Old 01-31-2008, 11:47 AM   #9
Icy
Pro Starter
 
Join Date: Sep 2003
Location: Toledo - Spain
Quote:
Originally Posted by gstelmack View Post
PHP doesn't let you write that block like:

if(!isset($year)){$year='s.year = 2014';$table='stats2014';}
elseif($year=='Career'){$year = 's.year > 2003';$table='statsALL';}
else{$year = 's.year = '+$year;$table='stats'+$year;}

?

Yup, good way to group all the conditions, but in this case there is a problem with this:

$year = 's.year = '+$year; and then this $table='stats'+$year;

As in that sentence, and for example for 2014

$table = 'stats
s.year = 2014'

instead of what is wanted:$table = stats2014

the problem is using the same variable $year for two different things, instead i would use two variables, like $year and $yearQ.
That way i would use $year always to store the numerical year, and $yearQ to store the variable for the query,

for example if the year is 2014:

$year =
2014
$yearQ =
's.year = '+$year; (so $yearQ = 's.year = 2014')
$table = 'stats' + $year; (so $table = 'stats2014')
__________________


Last edited by Icy : 01-31-2008 at 03:00 PM.
Icy is offline   Reply With Quote
Old 01-31-2008, 12:13 PM   #10
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
Yeah, I wasn't paying close attention to syntax details (I know very little PHP), was just surprised at the giant IF block.
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Old 01-31-2008, 12:18 PM   #11
gottimd
Dearly Missed
(9/25/77-12/23/08)
 
Join Date: Nov 2003
Location: DC Suburbs
Quote:
Originally Posted by gstelmack View Post
Yeah, I wasn't paying close attention to syntax details (I know very little PHP), was just surprised at the giant IF block.

I have been learning in my spare 3 minutes that I have a day not working. Marcmoustache and Icy have been very helpful in guiding me in the right direction as I have been constantly screwing it up trying to learn php on my own. I think I am getting the hang of it, and I hope to be able to generate better reports for my online league with the info you keep putting out on the FOF Extractor!
__________________
NAFL New Orleans Saints GM/Co-Commish
MP Career Record: 114-85
NAFL Super Bowl XI Champs
In memory of Gavin Anthony: 7/22/08-7/26/08
gottimd is offline   Reply With Quote
Old 01-31-2008, 12:30 PM   #12
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
Quote:
Originally Posted by gottimd View Post
I have been learning in my spare 3 minutes that I have a day not working. Marcmoustache and Icy have been very helpful in guiding me in the right direction as I have been constantly screwing it up trying to learn php on my own. I think I am getting the hang of it, and I hope to be able to generate better reports for my online league with the info you keep putting out on the FOF Extractor!

Sorry, I'm doing lots of phone screens and interviews, so my code critique meter is pegged at the moment...
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 07:49 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.