/leaguetable.php
PHP | 282 lines | 210 code | 65 blank | 7 comment | 28 complexity | 9438c3abcff459d1baa7d89b3d0fc6ec MD5 | raw file
- <?php
- global $db;
-
- if($_POST['lid']) {
- $lid = $_POST['lid'];
- }
- else {
- $team = new Team2();
- $team->load($_COOKIE['team_id']);
-
- $lid = $team->league_id;
- }
-
- if($lid == '') {
- $league_name = $_COOKIE['league_name'];
- $lid = $_COOKIE['league_id'];
- $season_id = $_COOKIE['season_id'];
- }
-
-
- if($lid != '' && $lid != 0) {
- $sql = "Select * from leagues where league_id=$lid";
- $league = $db->sql_singlerow($sql) or die($db->sql_error());
-
- $league_name = $league['league_name'];
- $league_id = $lid;
-
- $sql = "SELECT *
- FROM seasons
- WHERE league_id= $lid
- ORDER BY season_id DESC
- LIMIT 1";
- $season = $db->sql_singlerow($sql) or die($db->sql_error());
-
- $season_id = $season['season_id'];
- }
- else {
- echo "You are not yet been allocated to aleague. Please try again soon";
- }
-
-
-
- if($season_id == 0 && $lid != 0) {
- die("<br><br><center>No Current Season</center>");
- }
-
- if($season_id) {
-
- $season = $db->sql_singlerow("select * from seasons where season_id=$season_id");
-
-
- table_open("75%");
- table_row_open();
- table_header($league_name . " - " . $season['season_name'], "center", 10);
- table_row_close();
-
- table_row_open();
- table_header("Position", "center");
- table_header("Team", "center");
- table_header("Played", "center");
- table_header("Won", "center");
- table_header("Drawn", "center");
- table_header("Lost", "center");
- table_header("Goals For", "center");
- table_header("Goals Against", "center");
- table_header("Difference", "center");
- table_header("Points", "center");
- table_row_close();
-
- if(!isset($_COOKIE['league_id'])) {
- die();
- }
-
-
- $sql = "Select team_id, team_name, league_goals_for, league_goals_against, league_points ";
- $sql .= "from teams where league_id=$league_id ";
- $sql .= "order by league_points desc, (league_goals_for - league_goals_against) desc, league_goals_for desc, team_name";
- $teams = $db->sql_query($sql) or die($db->sql_error());
-
- $row=0;
- while ($team = $db->sql_fetchrow($teams)) {
- //$row+= 1;
-
- $sql = "Select Count(*) as cnt from fixtures where (team_id_home=". $team["team_id"] ." or team_id_away=". $team['team_id'] .") and league_id=$league_id and season_id=$season_id and attendance>0";
- $played = $db->sql_singlerow($sql);
-
- table_row_open();
-
- $sql = "Select count(*) as cnt_home from fixtures where (goals_home > goals_away) and team_id_home=". $team["team_id"] . " and league_id=$league_id and season_id=$season_id and attendance>0";
- $home = $db->sql_singlerow($sql);
- $home_won = $home['cnt_home'];
-
- $sql = "Select count(*) as cnt_away from fixtures where (goals_away > goals_home) and team_id_away=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
- $away = $db->sql_singlerow($sql);
- $away_won = $away['cnt_away'];
-
- $sql = "Select count(*) as cnt_home from fixtures where (goals_home < goals_away) and team_id_home=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
- $home = $db->sql_singlerow($sql);
- $home_lost = $home['cnt_home'];
-
- $sql = "Select count(*) as cnt_away from fixtures where (goals_away < goals_home) and team_id_away=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
- $away = $db->sql_singlerow($sql);
- $away_lost = $away['cnt_away'];
-
- $sql = "Select count(*) as cnt from fixtures where (goals_away = goals_home) and (team_id_away=". $team["team_id"] . " or team_id_home=". $team["team_id"] . ") and league_id=$league_id and season_id=$season_id and attendance>0";
- $draw = $db->sql_singlerow($sql);
- $drawn = $draw['cnt'];
-
- table_data($row, "center");
- $url="<a href=\"index.php?page=teamview&tid=". $team['team_id'] ."\">". $team['team_name'] ."</a>";
- table_data($url, "center");
- table_data($played['cnt'], "center");
- table_data($home_won + $away_won, "center");
- table_data($drawn, "center");
- table_data($home_lost + $away_lost, "center");
- table_data($team['league_goals_for'], "center");
- table_data($team['league_goals_against'], "center");
- table_data($team['league_goals_for'] - $team['league_goals_against'], "center");
- table_data($team['league_points'], "center");
-
- table_row_close();
- }
- table_close();
- echo "<br><br>";
-
-
- if(isset($_COOKIE['season_id'])) {
- //*******************************
- // league stats
- //
- table_open("75%");
- table_row_open();
- table_header("League Statistics", "center", 12);
- table_row_close();
-
- table_row_open();
- table_header("Top Scorers", "center", 2);
- table_header("Passes Completed %", "center", 2);
- table_header("Interceptions Completed %", "center", 2);
- table_header("Dribbles Completed % ", "center", 2);
- table_header("Tackles Completed % ", "center", 2);
- table_row_close();
-
- $scorers_sql = "select player_name, p.player_id, count(goal_id) as goals from players p ";
- $scorers_sql .= "inner join history_goals h on h.player_id = p.player_id ";
- $scorers_sql .= "inner join fixtures f on f.fixture_id = h.fixture_id ";
- $scorers_sql .= "where f.season_id=$season_id group by h.player_id ";
- $scorers_sql .= "order by goals desc, p.player_name asc ";
- $scorers = $db->sql_query($scorers_sql);
-
- $passers_sql = "select player_id, player_name, ((";
- $passers_sql .= "(select count(*) from history_passes, fixtures ";
- $passers_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
- $passers_sql .= "and history_passes.player_id = players.player_id ";
- $passers_sql .= "and pass_completed=1 and season_id=$season_id) / ";
- $passers_sql .= "(select count(*) from history_passes, fixtures ";
- $passers_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
- $passers_sql .= "and history_passes.player_id = players.player_id and season_id=$season_id) ) * 100) as pert ";
- $passers_sql .= "from players order by pert desc ";
- $passers = $db->sql_query($passers_sql);
-
- $intercept_sql = "select player_id, player_name, ((";
- $intercept_sql .= "(select count(*) from history_passes, fixtures ";
- $intercept_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
- $intercept_sql .= "and history_passes.opponent_id = players.player_id ";
- $intercept_sql .= "and pass_completed=0 and season_id=$season_id) / ";
- $intercept_sql .= "(select count(*) from history_passes, fixtures ";
- $intercept_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
- $intercept_sql .= "and history_passes.opponent_id = players.player_id and season_id=$season_id)) * 100) as pert ";
- $intercept_sql .= "from players order by pert desc ";
- $intercepters = $db->sql_query($intercept_sql);
-
- $tacklers_sql = "select player_id, player_name, ((";
- $tacklers_sql .= "(select count(*) from history_tackles, fixtures ";
- $tacklers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
- $tacklers_sql .= "and history_tackles.player_id = players.player_id ";
- $tacklers_sql .= "and successful=1 and season_id=$season_id) / ";
- $tacklers_sql .= "(select count(*) from history_tackles, fixtures ";
- $tacklers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
- $tacklers_sql .= "and history_tackles.player_id = players.player_id and season_id=$season_id)) * 100) as pert ";
- $tacklers_sql .= "from players order by pert desc";
- $tacklers = $db->sql_query($tacklers_sql);
-
- $dribblers_sql = "select player_id, player_name, ((";
- $dribblers_sql .= "(select count(*) from history_tackles, fixtures ";
- $dribblers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
- $dribblers_sql .= "and history_tackles.tackled_player_id = players.player_id ";
- $dribblers_sql .= "and successful=0 and season_id=$season_id) / ";
- $dribblers_sql .= "(select count(*) from history_tackles, fixtures ";
- $dribblers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
- $dribblers_sql .= "and history_tackles.tackled_player_id = players.player_id and season_id=$season_id)) * 100) as pert ";
- $dribblers_sql .= "from players order by pert desc";
- $dribblers = $db->sql_query($dribblers_sql);
-
-
-
- for($i=0; $i < 10; $i++) {
- $scorer = $db->sql_fetchrow($scorers);
- $passer = $db->sql_fetchrow($passers);
- while(($passer['pert'] > 95) | ($passer['pert'] == '')) {
- if(!$passer = $db->sql_fetchrow($passers)) {
- break;
- }
- }
-
- $intercepter = $db->sql_fetchrow($intercepters);
- while(($intercepter['pert'] > 95) | ($intercepter['pert'] == '')) {
- if(!$intercepter = $db->sql_fetchrow($intercepters)) {
- break;
- }
- }
-
- $tackler = $db->sql_fetchrow($tacklers);
- while(($tackler['pert'] > 95) | ($tackler['pert'] == '')) {
- if(!$tackler = $db->sql_fetchrow($tacklers)) {
- break;
- }
- }
-
- $dribbler = $db->sql_fetchrow($dribblers);
- while(($dribbler['pert'] > 95) | ($dribbler['pert'] == '')) {
- if(!$dribbler = $db->sql_fetchrow($dribblers)) {
- break;
- }
- }
-
-
- table_row_open();
- table_data("<a href='index.php?page=player&player_id=". $scorer['player_id'] ."'>" . $scorer['player_name'] . "</a>", "left");
- table_data($scorer['goals'], "center");
-
-
- table_data("<a href='index.php?page=player&player_id=". $passer['player_id'] ."'>" . $passer['player_name'] . "</a>", "left");
- table_data($passer['pert'], "center");
-
- table_data("<a href='index.php?page=player&player_id=". $intercepter['player_id'] ."'>" . $intercepter['player_name'] . "</a>", "left");
- table_data($intercepter['pert'], "center");
-
- table_data("<a href='index.php?page=player&player_id=". $dribbler['player_id'] ."'>" . $dribbler['player_name'] . "</a>", "left");
- table_data($dribbler['pert'], "center");
-
-
- table_data("<a href='index.php?page=player&player_id=". $tackler['player_id'] ."'>" . $tackler['player_name'] . "</a>", "left");
- table_data($tackler['pert'], "center");
-
- table_row_close();
- }
-
- table_close();
- echo "<br><br>";
- }
-
- //*******************************
- // link to other leagues
- //
-
- $sql = "Select * from leagues where league_id<> $league_id";
- $leagues = $db->sql_query($sql) or die($db->sql_error());
-
- if($db->sql_numrows($sql)){
-
-
- table_open("75%");
- table_row_open();
- table_header("Other Leagues", "center", 10);
- table_row_close();
-
-
-
- while ($league = $db->sql_fetchrow($leagues)) {
-
- table_row_open();
-
- table_data("<a href='index.php?page=leaguetable&lid=". $league['league_id'] ."'>".$league['league_name']."</a>", "center");
-
- table_row_close();
- }
-
- table_close();
- }
- }
- ?>