![]() |
|
|
#1 | |||
|
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:
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. |
|||
|
|
|
|
|
#2 |
|
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! |
|
|
|
|
|
#3 | |
|
Dearly Missed
(9/25/77-12/23/08) Join Date: Nov 2003
Location: DC Suburbs
|
Quote:
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 |
|
|
|
|
|
|
#4 |
|
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:
__________________
|
|
|
|
|
|
#5 |
|
H.S. Freshman Team
Join Date: Jun 2005
|
Yep, sorry gottimd, my dodgy code, what bonegavel said will work
|
|
|
|
|
|
#6 |
|
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 |
|
|
|
|
|
#7 |
|
H.S. Freshman Team
Join Date: Jun 2005
|
yep
|
|
|
|
|
|
#8 |
|
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 |
|
|
|
|
|
#9 | |
|
Pro Starter
Join Date: Sep 2003
Location: Toledo - Spain
|
Quote:
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 = 'statss.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. |
|
|
|
|
|
|
#10 |
|
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 |
|
|
|
|
|
#11 | |
|
Dearly Missed
(9/25/77-12/23/08) Join Date: Nov 2003
Location: DC Suburbs
|
Quote:
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 |
|
|
|
|
|
|
#12 | |
|
Pro Starter
Join Date: Oct 2000
Location: Cary, NC
|
Quote:
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 |
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|