Dutch
09-24-2011, 10:23 AM
I need some help and am hoping some of the seasoned PHP/MySQL vets can help me out here. Forgive the look of the code, I'm just a hobbyist here.
My current project is to determine "Games Back" in a standings (PHP) page. I've been stuck on this for a while now. Although the following code is broken, it has all the moving parts that I think I need for the GB column of a standings page.
I've got two SELECT statements, so my first question is how do I handle that? Can (and should) I nest the queries? Should I set the @wl_diff in a different PHP variable? (the book suggests I shouldn't do that). I don't know what to do next.
$sql11 = 'SELECT @wl_diff:=MAX((sum(Score>OppScore))-(sum(OppScore>Score))) FROM fof_teamschedule';
. 'SELECT'
. ' fof_teams.ID,'
. ' fof_teams.CityName,'
. ' fof_teams.Nickname,'
. ' fof_teams.Conference,'
. ' fof_teams.Division,'
. ' TeamID,'
. ' sum(Score>OppScore) AS Wins,'
. ' sum(OppScore>Score) AS Losses,'
. ' sum(Score=OppScore) AS Ties,'
. ' sum(Score>OppScore)/(sum(Score>OppScore)/sum Score>OppScore) AS PCT,'
. ' (@wl_diff - (sum(Score>OppScore)-sum(Score>OppScore))) / 2 AS GB,'
. ' sum(Score),'
. ' sum(OppScore)'
. ' FROM fof_teamschedule, fof_teams'
. ' WHERE fof_teams.ID = TeamID AND Conference=1 AND Division=1 AND Year=2024 AND Week>5 AND Week<23 '
. ' GROUP BY TeamID'
. ' ORDER BY GB DESC, TeamID DESC';
Any and all suggestions and complaints about my code will be accepted as gifts. Thanks.
My current project is to determine "Games Back" in a standings (PHP) page. I've been stuck on this for a while now. Although the following code is broken, it has all the moving parts that I think I need for the GB column of a standings page.
I've got two SELECT statements, so my first question is how do I handle that? Can (and should) I nest the queries? Should I set the @wl_diff in a different PHP variable? (the book suggests I shouldn't do that). I don't know what to do next.
$sql11 = 'SELECT @wl_diff:=MAX((sum(Score>OppScore))-(sum(OppScore>Score))) FROM fof_teamschedule';
. 'SELECT'
. ' fof_teams.ID,'
. ' fof_teams.CityName,'
. ' fof_teams.Nickname,'
. ' fof_teams.Conference,'
. ' fof_teams.Division,'
. ' TeamID,'
. ' sum(Score>OppScore) AS Wins,'
. ' sum(OppScore>Score) AS Losses,'
. ' sum(Score=OppScore) AS Ties,'
. ' sum(Score>OppScore)/(sum(Score>OppScore)/sum Score>OppScore) AS PCT,'
. ' (@wl_diff - (sum(Score>OppScore)-sum(Score>OppScore))) / 2 AS GB,'
. ' sum(Score),'
. ' sum(OppScore)'
. ' FROM fof_teamschedule, fof_teams'
. ' WHERE fof_teams.ID = TeamID AND Conference=1 AND Division=1 AND Year=2024 AND Week>5 AND Week<23 '
. ' GROUP BY TeamID'
. ' ORDER BY GB DESC, TeamID DESC';
Any and all suggestions and complaints about my code will be accepted as gifts. Thanks.