function golf_career_stats($player) { //build tables based on position $html = ''; $html .= '<table class="player_stats_table table table-condensed table-striped">'; $html .= '<thead>'; //add table headers $html .= '<tr><th align="center" width="50"><div class="th-inner">YEAR</div></th><th align="center" width="50"><div class="th-inner" title="Tournaments Played">Tournaments</div></th>'. '<th width="50"><div class="th-inner" title="Wins">Wins</div></th><th width="50"><div class="th-inner" title="Scoring Average">Scoring Average</div></th><th width="50"><div class="th-inner" title="Cuts Made">Cuts Made</div></th>'. '<th width="50"><div class="th-inner" title="Top 10 Finish">Top 10</div></th><th width="50"><div class="th-inner" title="Top 25 Finish">Top 25</div></th><th width="50"><div class="th-inner" title="Earnings">Earnings</div></th>'. '</tr>'; $html .= '</thead><tbody>'; //current season $qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "golf" ORDER BY season DESC LIMIT 1'); $current = $qcur->row(); $current_season = $current->season; if(!function_exists('career_rows')) { function career_rows($query,$year,$position='',$zero,$team='') { $stat_fields = array('events-played-events','wins','scoring-avg','cuts-made','top-finish-top10','top-finish-top25','earnings-amount'); //zero out things to avoid errors with missing stats //initially set everything to zero to avoid errors with missing data /* echo "<pre>"; print_r($zero); echo "</pre>"; foreach($zero->row() as $zero_array){ $c_stats[$zero_array->statkey] = 0; } */ foreach($query->result() as $stats_array) { $c_stats[$stats_array->statkey] = $stats_array->statvalue; } $c_stats['earnings-amount'] = '$'.number_format($c_stats['earnings-amount'],0,'.',','); //start building the output $html = '<tr><td>'.$year.'</td>'; //add all the stats foreach($stat_fields as $n) { if(isset($c_stats[$n])) { $html .= '<td>'.(is_numeric($c_stats[$n])?round($c_stats[$n],2):$c_stats[$n]).'</td>'; } else { $html .= '<td>N/A</td>'; } } $html .= '</tr>'; unset($c_stats); return $html; } } //get career totals $this->db->where('player_id',$player); $this->db->where('year',0); $query=$this->db->get('sport_player_career'); if($query->num_rows() > 0) { $zero=$this->db->query("SELECT DISTINCT(statkey) FROM ci_sport_player_career WHERE 1"); $html .= career_rows($query,'CAREER','',$zero); } //check if player has stats over last 25 years for($i = $current_season; $i > $current_season-25; $i--) { /*$this->db->where('player_id',$player); $this->db->where('year',$i); $query=$this->db->get('sport_player_career'); if($query->num_rows() > 0) { $html .= career_rows($query,$i,$position,$zero); }*/ $this->db->where('player_id',$player); $this->db->where('year',$i); $query=$this->db->get('sport_player_career'); if($query->num_rows() > 0) { $html .= career_rows($query,$i,'',$zero,''); } } $html .= '</tbody>'; $html .= '</table>'; return $html; }
function nfl_career_stats($player, $position, $team) { //build tables based on position $html = ''; $html .= '<table class="player_stats_table table table-condensed table-striped">'; $html .= '<thead>'; //add table headers switch ($position) { case 'QB': $html .= '<tr><th colspan="2"><div class="th-inner"></div></th><th colspan="9"><div class="th-inner">PASSING</div></th><th colspan="5"><div class="th-inner">RUSHING</div></th><th colspan="4"><div class="th-inner">FUMBLES</div></th></tr>'. '<tr><th align="center"><div class="th-inner2">YEAR</div></th><th align="center"><div class="th-inner2">G</div></th>'. '<th class="break"><div class="th-inner2">COMP</div></th><th><div class="th-inner2">ATT</div></th><th><div class="th-inner2">PCT</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th><th><div class="th-inner2">INT</div></th><th><div class="th-inner2">RATE</div></th>'. '<th class="break"><div class="th-inner2">ATT</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th>'. '<th class="break"><div class="th-inner2">FUM</div></th><th><div class="th-inner2">LOST</div></th>'. '</tr>'; break; case 'RB': $html .= '<tr><th colspan="2"><div class="th-inner"></div></th><th colspan="5"><div class="th-inner">RUSHING</div></th><th colspan="5"><div class="th-inner">RECEIVING</div></th><th colspan="4"><div class="th-inner">FUMBLES</div></th></tr>'. '<tr><th align="center"><div class="th-inner2">YEAR</div></th><th align="center"><div class="th-inner2">G</div></th>'. '<th class="break"><div class="th-inner2">ATT</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th>'. '<th class="break"><div class="th-inner2">REC</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th>'. '<th class="break"><div class="th-inner2">FUM</div></th><th><div class="th-inner2">LOST</div></th>'. '</tr>'; break; case 'TE': case 'WR': $html .= '<tr><th colspan="2"><div class="th-inner"></div></th><th colspan="5"><div class="th-inner">RECEIVING</div></th><th colspan="5"><div class="th-inner">RUSHING</div></th><th colspan="4"><div class="th-inner">FUMBLES</div></th></tr>'. '<tr><th align="center"><div class="th-inner2">YEAR</div></th><th align="center"><div class="th-inner2">G</div></th>'. '<th class="break"><div class="th-inner2">REC</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th>'. '<th class="break"><div class="th-inner2">ATT</div></th><th><div class="th-inner2">YDS</div></th><th><div class="th-inner2">AVG</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">TD</div></th>'. '<th class="break"><div class="th-inner2">FUM</div></th><th><div class="th-inner2">LOST</div></th>'. '</tr>'; break; case 'K': $html .= '<tr><th colspan="2"><div class="th-inner"></div></th><th colspan="6"><div class="th-inner">FIELD GOALS</div></th><th colspan="5"><div class="th-inner">PAT</div></th></tr>'. '<tr><th align="center"><div class="th-inner2">YEAR</div></th><th align="center"><div class="th-inner2">G</div></th>'. '<th class="break"><div class="th-inner2">FGA</div></th><th><div class="th-inner2">FGM</div></th><th><div class="th-inner2">PCT</div></th><th><div class="th-inner2">LNG</div></th><th><div class="th-inner2">40-49FG</div></th><th><div class="th-inner2">50+</div></th>'. '<th class="break"><div class="th-inner2">XPA</div></th><th><div class="th-inner2">XPM</div></th><th><div class="th-inner2">PCT</div></th>'. '</tr>'; break; } $html .= '</thead><tbody>'; //current season $qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "nfl" ORDER BY season DESC LIMIT 1'); $current = $qcur->row(); $current_season = $current->season; if(!function_exists('career_rows')) { function career_rows($query,$year,$position='',$zero) { switch($position) { case 'QB': $stat_fields = array('games','passing-completions','passing-attempts','passing-completions-percentage','passing-yards','passing-completions-average','passing-long-yards','passing-touchdowns','interceptions','qb-rating','rushing-attempts','rushing-yards','rushing-yards-average','rushing-long-yards','rushing-touchdowns','fumbles','fumbles-lost-fumbles'); break; case 'RB': $stat_fields = array('games','rushing-attempts','rushing-yards','rushing-yards-average','rushing-long-yards','rushing-touchdowns','receptions','receiving-yards','receiving-yards-average','receiving-long-yards','receiving-touchdowns','fumbles','fumbles-lost-fumbles'); break; case 'TE': case 'WR': $stat_fields = array('games','receptions','receiving-yards','receiving-yards-average','receiving-long-yards','receiving-touchdowns','rushing-attempts','rushing-yards','rushing-yards-average','rushing-long-yards','rushing-touchdowns','fumbles','fumbles-lost-fumbles'); break; case 'K': $stat_fields = array('games','field-goals-attempted','field-goals-made','field-goals-percentage','long-field-goal-yards','field-goals-40-49-made','field-goals-50-plus-made','extra-points-attempted','extra-points-made','extra-points-percentage'); break; } //zero out things to avoid errors with missing stats //initially set everything to zero to avoid errors with missing data foreach($zero->result() as $zero_array){ $c_stats[$zero_array->statkey] = 0; } foreach($query->result() as $stats_array) { $c_stats[$stats_array->statkey] = $stats_array->statvalue; } //start building the output $html = '<tr><td>'.$year.'</td>'; //add all the stats foreach($stat_fields as $n) { if(isset($c_stats[$n])) { $html .= '<td>'.(float)$c_stats[$n].'</td>'; } else { $html .= '<td>0</td>'; } } $html .= '</tr>'; return $html; } } //get career totals $this->db->where('player_id',$player); $this->db->where('year',0); $query=$this->db->get('sport_player_career'); if($query->num_rows() > 0) { $zero=$this->db->query("SELECT DISTINCT(statkey) FROM ci_sport_player_career WHERE 1"); $html .= career_rows($query,'CAREER',$position,$zero); } //check if player has stats over last 25 years for($i = $current_season; $i > $current_season-25; $i--) { $this->db->where('player_id',$player); $this->db->where('year',$i); $query=$this->db->get('sport_player_career'); if($query->num_rows() > 0) { $html .= career_rows($query,$i,$position,$zero); } } $html .= '</tbody>'; $html .= '</table>'; return $html; }