= 9, action_log.end desc limit 1"; $run_logss = mysqli_query($db_conn,$select_logss); if($run_logss->num_rows == 0){ // if no games this season then get the last season with games unset($run_logss); $select_logss = "select * from action_log join seasons on seasons.season_id = action_log.season_id WHERE action_log.player_id = '".$_REQUEST['player_id']."' order by seasons.season_end desc, action_log.end >= 9, action_log.end desc limit 1"; $run_logss = mysqli_query($db_conn,$select_logss); } $rows_logss = mysqli_fetch_assoc($run_logss); // if there is no picture for the current season get the latest picture available if($rows_logss['head_shot_thumb'] == ""){ $getP = mysqli_fetch_assoc(mysqli_query($db_conn,"select head_shot_thumb from action_log WHERE action_log.player_id = '".$_REQUEST['player_id']."' AND head_shot_thumb != '' ORDER BY log_id DESC ")); $rows_logss['head_shot_thumb'] = $getP["head_shot_thumb"]; } // trick to show transcona railer expres instead of the old team if($rows_logss['team_id'] == 13)$rows_logss['team_id'] = 16; $select_team_page = "select * from teams WHERE team_id = '".$rows_logss['team_id']."'"; $run_team_page = mysqli_query($db_conn,$select_team_page) or die (mysql_error()); $row_team_page = mysqli_fetch_assoc($run_team_page); $cssPage = str_replace(".css", "", $row_team_page['css']); $_POST['team_selection'] = $row_team_page['team_id']; $date2 = explode("-",date("d-m-Y")); $date_cu = mktime("0", "0", "1" , $date2[1], $date2[0], $date2[2]); $_REQUEST['team_id'] = $row_team_page['team_id']; $general_team_id = $row_team_page['team_id']; ############################################################################################################ //////////selecting latest photos /*$select_logss2 = "select * from action_log join seasons on seasons.season_id = action_log.season_id WHERE action_log.player_id = '".$_REQUEST['player_id']."' AND action_log.action_shot_thumb_1 <> '' order by seasons.season_start desc, action_log.start desc limit 1"; $run_logss2 = mysqli_query($db_conn,$select_logss2) or die (mysql_error()); $rows_logss2 = mysqli_fetch_assoc($run_logss2);*/ include("includes/team_timings.php"); /// create description text // 1. check if he is still active $x1 = mysqli_query($db_conn,"SELECT team_id FROM action_log WHERE player_id = '".intval($_REQUEST['player_id'])."' AND season_id='{$row_general_settings["season_id"]}' ORDER BY log_id DESC"); if($x1->num_rows>0){ // active player right now //one or multiple teams $x2 = mysqli_query($db_conn,"SELECT DISTINCT action_log.team_id, teams.team_name1, teams.team_name2, log_id FROM `action_log` JOIN teams ON action_log.team_id = teams.team_id WHERE `player_id` = '".intval($_REQUEST['player_id'])."' ORDER BY log_id DESC"); if($x2->num_rows==1){// one team // get the first year when he played $x3 = mysqli_fetch_assoc(mysqli_query($db_conn," SELECT seasons.season_start FROM `action_log` JOIN seasons ON action_log.season_id=seasons.season_id WHERE action_log.player_id = '".intval($_REQUEST['player_id'])."' ORDER BY seasons.season_start ASC LIMIT 0,1 ")); $description = $row_player_page['name1']." ".$row_player_page['name3']." is a ".$position_names[$rows_logss['position_id']]." currently playing for the ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." of the MMJHL and has played in the MMJHL since {$x3["season_start"]}."; } elseif($x2->num_rows==2){ // 2 teams while($xrow = mysqli_fetch_assoc($x2)){$getInfo[] = $xrow;} if(!isTeamSite()) { $description = $row_player_page['name1']." ".$row_player_page['name3']." is a ".$position_names[$rows_logss['position_id']]." currently playing for the ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." of the MMJHL and has also played for the ".$getInfo[1]["team_name1"]." ".$getInfo[1]["team_name2"]."."; } else { $description = $row_player_page['name1']." ".$row_player_page['name3']." is a ".$position_names[$rows_logss['position_id']]." currently playing for the ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." of the MMJHL."; } } else{ // more than 2 teams $i = 1; while($xrow = mysqli_fetch_assoc($x2)){ if($i==2)$teamsplayed = $xrow["team_name1"]." ".$xrow["team_name2"]; else if($i>2) $teamsplayed .= " and the ".$xrow["team_name1"]." ".$xrow["team_name2"]; $i++; } if(!isTeamSite()) { $description = $row_player_page['name1']." ".$row_player_page['name3']." is a ".$position_names[$rows_logss['position_id']]." currently playing for the ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." of the MMJHL and has also played for the $teamsplayed."; } else { $description = $row_player_page['name1']." ".$row_player_page['name3']." is a ".$position_names[$rows_logss['position_id']]." currently playing for the ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." of the MMJHL."; } } } else{ // ########################## total games and goals / gaa for the player $run_log1 = mysqli_query($db_conn,"select DISTINCT team_id from action_log join seasons on seasons.season_id = action_log.season_id WHERE action_log.player_id = '".$row_player_page['player_id']."' order by seasons.season_start , action_log.log_id ASC "); while($row_log1 = mysqli_fetch_assoc($run_log1)) { ///counting games $select_count_total_games = "select count(game_id) as total_games from games join game_types ON games.game_type_id=game_types.game_type_id WHERE game_types.game_type_name = 'League' AND ((team1_players LIKE '%|".$row_player_page['player_id']."|%' AND team1 = '".$row_log1['team_id']."') OR (team2_players LIKE '%|".$row_player_page['player_id']."|%' AND team2 = '".$row_log1['team_id']."')) AND game_over = 1"; $run_count_total_games2 = mysqli_query($db_conn,$select_count_total_games); $row_count_total_games2 = mysqli_fetch_assoc($run_count_total_games2); $sumGames = $sumGames + $row_count_total_games2['total_games']; ///counting goals GENERAL $run_count_total_goals2 = mysqli_query($db_conn,"select count(scorers.scorer_id) as total_goals from scorers join games on games.game_id = scorers.game_id join game_types ON games.game_type_id=game_types.game_type_id WHERE game_types.game_type_name = 'League' AND scorers.scorer = '".$row_player_page['player_id']."' AND games.game_over = 1 AND scorers.team_id = '".$row_log1['team_id']."'"); $row_count_total_goals2 = mysqli_fetch_assoc($run_count_total_goals2); ///counting assists $run_count_total_assists2 = mysqli_query($db_conn,"select count(scorers.scorer_id) as total_assists from scorers join games on games.game_id = scorers.game_id join game_types ON games.game_type_id=game_types.game_type_id WHERE game_types.game_type_name = 'League' AND (scorers.assister1 = '".$row_player_page['player_id']."' OR scorers.assister2 = '".$row_player_page['player_id']."') AND games.game_over = 1 AND scorers.team_id = '".$row_log1['team_id']."'"); $row_count_total_assists2 = mysqli_fetch_assoc($run_count_total_assists2); $sumPoints = $sumPoints + ($row_count_total_goals2['total_goals'] + $row_count_total_assists2["total_assists"]); if($rows_logss['position_id'] == 3){ //selecting total time $run_total_time2 = mysqli_query($db_conn,"select sum(goaltenders.time1) as minutes, sum(goaltenders.time2) as seconds, sum(ga) as total_goals_against from goaltenders join games on games.game_id = goaltenders.game_id join game_types ON games.game_type_id=game_types.game_type_id WHERE game_types.game_type_name = 'League' AND goaltenders.player_id = '".$row_player_page['player_id']."' AND games.game_over = 1 AND goaltenders.team_id = '".$row_log1['team_id']."'"); $row_total_time2 = mysqli_fetch_assoc($run_total_time2); ############################################################## GETTING TOTAL TIME $total_secondsxx = 0; $total_secondsxx = $row_total_time2['seconds'] + ($row_total_time2['minutes'] * 60); $total_s = $total_s + $total_secondsxx; $sumGaa = $sumGaa + $row_total_time2['total_goals_against']; } } if($rows_logss['position_id'] == 3){ $number = $total_s > 0 ? $sumGaa/($total_s/3600) : 0; $totalG = "a GAA of ".number_format($number, 2); } // goalie info else{$totalG = $sumPoints." total points";} // player info //echo "== ".$sumGames." - ".$sumGaa." - ".$totalG; /// get first and last years when he played $getYears = mysqli_fetch_assoc(mysqli_query($db_conn,"SELECT MIN(seasons.season_start) as minp, MAX(seasons.season_end) as maxp FROM `action_log` JOIN seasons ON action_log.season_id=seasons.season_id WHERE action_log.`player_id` = ".$row_player_page['player_id'])); ######################################################################################### //one or multiple teams $x2 = mysqli_query($db_conn," SELECT DISTINCT action_log.team_id, action_log.position_id, teams.team_name1, teams.team_name2 FROM `action_log` JOIN teams ON action_log.team_id = teams.team_id WHERE `player_id` = '".intval($_REQUEST['player_id'])."' ORDER BY log_id DESC"); if($x2->num_rows==1){// one team $description = $row_player_page['name1']." ".$row_player_page['name3']." played ".$position_names[$rows_logss['position_id']]." in the MMJHL from ".$getYears["minp"]."-".$getYears["maxp"]." and was a member of the ".$row_team_page['team_name1']." ".$row_team_page['team_name2'].", having played in $sumGames games with $totalG."; } elseif($x2->num_rows==2){ // 2 teams while($xrow = mysqli_fetch_assoc($x2)){$getInfo[] = $xrow;} if($getInfo[1]["team_name1"] == $row_team_page['team_name1']){$getInfo[1] = $getInfo[0];} if($row_team_page['team_name1'] == $getInfo[1]["team_name1"]){ $teams_text = $row_team_page['team_name1']." ".$row_team_page['team_name2']; } else{ $teams_text = $row_team_page['team_name1']." ".$row_team_page['team_name2']." and the ".$getInfo[1]["team_name1"]." ".$getInfo[1]["team_name2"]; } $description = $row_player_page['name1']." ".$row_player_page['name3']." played ".$position_names[$rows_logss['position_id']]." in the MMJHL from ".$getYears["minp"]."-".$getYears["maxp"]." and was a member of the ".$teams_text.", having played in $sumGames games with $totalG."; } else{ // more than 2 teams $i = 1; $total_number_of_teams = $x2->num_rows; while($xrow = mysqli_fetch_assoc($x2)){ if($teams_used != "" && in_array($xrow["team_id"], $teams_used)){ $total_number_of_teams--; $i--; } else{ if($i == $total_number_of_teams)$teamsplayed .= "and the ".$xrow["team_name1"]." ".$xrow["team_name2"].", "; else $teamsplayed .= $xrow["team_name1"]." ".$xrow["team_name2"].", "; $i++; $teams_used[] = $xrow["team_id"]; } } $description = $row_player_page['name1']." ".$row_player_page['name3']." played ".$position_names[$rows_logss['position_id']]." in the MMJHL from ".$getYears["minp"]."-".$getYears["maxp"]." and was a member of the ".$teamsplayed."having played in $sumGames games with $totalG."; } } $title = $row_player_page['name1']." ".$row_player_page['name3']." - #".$row_player_page['number']." ".$position_names[$rows_logss['position_id']]." - ".$row_team_page['team_name1']." ".$row_team_page['team_name2']." - MMJHL"; if(isTeamSite()) { $title = sprintf("%s %s - #%s %s | %s", $row_player_page['name1'], $row_player_page['name3'], $row_player_page['number'], $position_names[$rows_logss['position_id']], $row_team_page['team_domain']); // $description = ""; } // get the tea ?>