Location: PHPKode > projects > BaseballNuke > baseballNuke-2.0/blocks/block-TopBatters.php
<?php
$TeamLeaders=3;
/*
This file is part of baseballNuke.
Created by Shawn Grimes http://claimid.com/shawn

baseballNuke is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

baseballNuke is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with baseballNuke; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

if (eregi("block-Name_of_Block.php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}


	$TEAM_NAME=$defaultTeam;

global $prefix, $multilingual, $currentlang, $dbi, $boxTitle, $content, $pollcomm, $user, $cookie, $userinfo;

opentable2();
for ($MyCounter=0; $MyCounter<=5; $MyCounter++)
{
	$content.="<table>";

if ($MyCounter ==0){ $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In Hits</th></tr>";}
else if ($MyCounter ==1) { $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In Home Runs</th></tr>";}
else if ($MyCounter ==2) { $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In RBI`s</th></tr>";}
else if ($MyCounter ==3) { $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In Best Batting Average</th></tr>";}
else if ($MyCounter ==4) { $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In Slugging Percentage</th></tr>";}
else if ($MyCounter ==5) { $content.="<tr bgcolor=$bgcolor2><th colspan=20>Team Leader In On Base Percentage</th></tr>";}


	$content.="	 <tr bgcolor=$bgcolor2>
       	       <td width=25><font color=$textcolor1><b>#</b></font></td>
               <td width=125><font color=$textcolor1><b>Batting</b></font></td>
               <td width=25><font color=$textcolor1><b>AB</b></font></td>
               <td width=25><font color=$textcolor1><b>R</b></font></td>
               
               <td width=25><font color=$textcolor1><b>2B</b></font></td>
               <td width=25><font color=$textcolor1><b>3B</b></font></td>
               <td width=25><font color=$textcolor1><b>HR</b></font></td>
               <td width=25><font color=$textcolor1><b>RE</b></font></td>
               <td width=25><font color=$textcolor1><b>FC</b></font></td>
               <td width=25><font color=$textcolor1><b>HP</b></font></td>

               <td width=25><font color=$textcolor1><b>RBI</b></font></td>
               <td width=35 align=center><font color=$textcolor1><b>BA</b></font></td>
               <td width=35 align=center><font color=$textcolor1><b>OBP</b></font></td>
	       <td width=35 align=center><font color=$textcolor1><b>SLG</b></font></td>
	       <td width=35 align=center><font color=$textcolor1><b>OPS</b></font></td>
	       <td width=25 align=center><font color=$textcolor1><b>BB</b></font></td>
               <td width=25 align=center><font color=$textcolor1><b>K</b></font></td>
               <td width=25 align=center><font color=$textcolor1><b>LOB</b></font></td>
               <td width=25 align=center><font color=$textcolor1><b>SB</b></font></td>
            </tr></font>");

//BATTING STATS

//order of most home hits.
if ($MyCounter ==0) {
  $content.="<td width=25><font color=$textcolor1><b>HP</b></font></td></tr></font>";
  $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum, sum(ba1b+ba2b+ba3b+baHR) as baH FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baH DESC";
  
}else if ($MyCounter ==1) {//order of most home runs.
  $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum, sum(baHR) as baHR FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baHR DESC";
}else if ($MyCounter ==2) {//order of most RBI.
   $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum, sum(baRBI) as baRBI FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baRBI DESC";
}else if ($MyCounter==3) {//order of most best Batting Average. ba = (hits/ab) & hits=ba1b+ba2b+ba3b+bahr.
  $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum, sum(ba1b+ba2b+ba3b+baHR)/sum(baAB) as baBA FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baBA DESC";
}else if ($MyCounter==4) {//order of best SP. sp = (ba1b+ba2b*2+ba3b*3+bahr*4/ab)
    $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum, sum(ba1b+ba2b*2+ba3b*3+baHR*4)/sum(baAB) as baSP FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baSP DESC";
}else if ($MyCounter==5) {//order of best OBP. OBP = ($hits+$baBB+$baRE+$baFC+$baHP)/($baAB+$baBB)
    $sqlString="SELECT ".$prefix."_baseballNuke_players.playerID, lastname, firstname, middlename, jerseyNum,sum(ba1b+ba2b+ba3b+baHR+baBB+baRE+baFC+baHP)/sum(baAB+baBB) as baOBP FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID ORDER BY baOBP DESC";
}

 $resultPlayers=sql_query($sqlString, $dbi);
 //echo "SQL: $sqlString<BR>";
 //for ($m=0; $m < sql_num_rows($resultPlayers, $dbi); $m++) {
 for ($m=0; $m < $TeamLeaders; $m++) {
   list($playerID, $lastname, $firstname, $middlename, $jerseyNum,$UselessNumber) = sql_fetch_row($resultPlayers, $dbi);
   echo "$playerID-$lastname,$firstname<BR>";
   $sqlString="SELECT sum(baRuns) as baR, sum(baAb) as baAB, sum(ba1b) as ba1b, sum(ba2b) as ba2b, sum(ba3b) as ba3b, sum(baHR) as baHR, sum(baRE) as baRE, sum(baFC) as baFC, sum(baHP) as baHP, sum(baRBI) as baRBI, sum(baBB) as baBB, sum(baK) as baK, sum(baLOB)as baLOB, sum(baSB) as baSB FROM ".$prefix."_baseballNuke_players,".$prefix."_baseballNuke_stats,".$prefix."_baseballNuke_schedule WHERE teamName='".$TEAM_NAME."' AND DATE_FORMAT(gameDate,\"%Y\")='".$_COOKIE["season"]."' AND ".$prefix."_baseballNuke_players.playerID=".$playerID." AND ".$prefix."_baseballNuke_players.playerID=".$prefix."_baseballNuke_stats.playerID AND ".$prefix."_baseballNuke_stats.gameID=".$prefix."_baseballNuke_schedule.gameID  AND ".$prefix."_baseballNuke_players.season=DATE_FORMAT(gameDate,\"%Y\") GROUP BY ".$prefix."_baseballNuke_players.playerID";// ORDER BY lastname,firstname ASC";
   //echo "SQL: $sqlString<BR>";
   $resultStats=sql_query($sqlString, $dbi);
   if($resultStats && sql_num_rows($resultStats, $dbi)){
     list($baR, $baAB, $ba1b, $ba2b, $ba3b, $baHR, $baRE, $baFC, $baHP, $baRBI, $baBB, $baK, $baLOB, $baSB) = sql_fetch_row($resultStats, $dbi);
     $hits=$ba1b+$ba2b+$ba3b+$baHR;
     //echo "<h1>$lastname, $firstname - $ba1b - $ba2b - $ba3b - $baHR - $baBB</h1>";
     $slg=round((($ba1b+($ba2b*2)+($ba3b*3)+($baHR*4))/$baAB),3);
     $slg=str_pad($slg,5,"0");
     if($slg=="1000"){
       $slg=substr($slg,-1);
     }else{
       $slg=substr($slg,1);
       $slg=str_replace("0000","0",$slg);
     }
     $obp= str_pad(str_replace("0.",".",round(($hits+$baBB+$baRE+$baFC+$baHP)/($baAB+$baBB),3)),4,"0",STR_PAD_RIGHT);
     if ($obp == "1000") { $obp = "1.000";}
     if ($obp == "0") { $obp = ".000";}
     /*$obp=str_pad($obp,5,"0");
      if($obp=="10000"){
      $obp=substr($obp,0,-1);
      }
      else{
      $obp=substr($obp,1);
      $obp=str_replace("0000","0",$obp);
      }
     */
     $ops=($obp+$slg);
     $ba=round($hits/$baAB,3);
     $ba=strval($ba);
     $ba=str_pad($ba,5,"0");
     if($ba=="10000"){
       $ba=substr($ba,0,-1);
     }else{
       $ba=substr($ba,1);
       $ba=str_replace("0000","0",$ba);
     }
   }
   print("<tr><td width=25><font size=2 color=#000000>".$jerseyNum."</td>");
   print("<td width=125><font size=2 color=#000000><a href=modules.php?name=".$module_name."&amp;page=playerStats&playerID=".$playerID.">".$lastname.", ".$firstname."</a></td>");
   if(sql_num_rows($resultStats, $dbi)){
     print("
			<td width=25><font size=2 color=#000000>".$baAB."</td>
			<td width=25><font size=2 color=#000000>".$baR."</td>
			<td width=25><font size=2 color=#000000>");
     if ($MyCounter ==0) print("<b>");
     print("$hits");
     if ($MyCounter ==0) print("</b>");
     print("</td>
			<td width=25><font size=2 color=#000000>".$ba2b."</td>
			<td width=25><font size=2 color=#000000>".$ba3b."</td>
			<td width=25><font size=2 color=#000000>");
     if ($MyCounter ==1) print("<b>");
     print ($baHR);
     if ($MyCounter ==1) print("</b>");
     print ("</td>
			<td width=25><font size=2 color=#000000>".$baRE."</td>
			<td width=25><font size=2 color=#000000>".$baFC."</td>
			<td width=25><font size=2 color=#000000>".$baHP."</td>
			<td width=25><font size=2 color=#000000>");
     if ($MyCounter ==2) print("<b>");
     print ($baRBI);
     if ($MyCounter ==2) print("</b>");
     print("</td>
			<td width=35><font size=2 color=#000000>");
     if ($MyCounter ==3) print("<b>");
     print ($ba);
     if ($MyCounter ==3) print("</b>");
     print ("</td>
			<td width=35><font size=2 color=#000000>");
     if ($MyCounter ==5) print("<b>");
     print ($obp);
     if ($MyCounter ==5) print("</b>");
     print ("</td>
			<td width=25><font size=2 color=#000000>");
     if ($MyCounter ==4) print("<b>");
     print ($slg);
     if ($MyCounter ==4) print("</b>");
     print ("</td>
			<td width=35><font size=2 color=#000000>$ops</td>
			<td width=25 align=center><font size=2 color=#000000>".$baBB."</td>
			<td width=25 align=center><font size=2 color=#000000>".$baK."</td>
			<td width=25 align=center><font size=2 color=#000000>".$baLOB."</td>
			<td width=25 align=center><font size=2 color=#000000>".$baSB."</td>");
   }
   print("</tr>");
 }
//removed totals, check out batStats to see what was here.
 print("</table>");
}

closetable2();
?>
Return current item: BaseballNuke