FamiHug

json

May 8th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. require_once 'config.php';
  3. startMySQLConnection();
  4. ?>
  5. <?php
  6.  
  7. function get_matches_by_date() {
  8.     $league = $_GET["league"];
  9.     $fd = $_GET["fd"];
  10.     $td = $_GET["td"];
  11.  
  12. //  $league = 2;
  13. //  $fd = strtotime("02-05-2012");
  14. //  $td = strtotime("14-05-2012");
  15.  
  16.     $sql = "
  17.         SELECT
  18.         matches.id AS id,
  19.         homeTeam.id AS homeTeamId,
  20.         homeTeam.name AS homeTeamName,
  21.         guestTeam.id AS guestTeamId,
  22.         guestTeam.name AS guestTeamName,
  23.         startDateTime AS matchDate,
  24.         channels.id AS channelId,
  25.         channels.name AS channelName,
  26.         matches.homeTeamGoals,
  27.         matches.guessTeamGoals AS guestTeamGoals,
  28.         stadiums.id AS stadiumId,
  29.         stadiums.name AS stadiumName,
  30.         leagues.id AS leagueId,
  31.         leagues.name AS leagueName,
  32.         rounds.id AS roundId,
  33.         rounds.name AS roundName
  34.         FROM `matches`
  35.         LEFT JOIN leagues ON leagues.id = leagueId
  36.         LEFT JOIN teams AS homeTeam On homeTeam.id = matches.homeTeamId
  37.         LEFT JOIN teams AS guestTeam ON guestTeam.id = matches.guessTeamId
  38.         LEFT JOIN rounds ON rounds.id = rounds.id
  39.         LEFT JOIN channels ON channels.id = channelId
  40.         LEFT JOIN stadiums ON stadiums.id = stadiumId
  41.         WHERE matches.roundId = rounds.id
  42.         AND matches.channelId = channels.id
  43.         AND matches.stadiumId = stadiums.id
  44.         AND matches.leagueId = $league
  45.         AND matches.startDateTime >= $fd
  46.         AND matches.startDateTime <= $td";
  47.  
  48.     ;
  49.  
  50.     $result = mysql_query($sql);
  51. //  echo $sql; echo "<br>";
  52.  
  53.     while ($row = mysql_fetch_array($result)) {
  54.         //tran dau chua dien ra
  55.         if ($row['matchDate'] > time()) {
  56.             $row['homeTeamGoals'] = -1;
  57.             $row['guestTeamGoals'] = -1;
  58.         }
  59.         $output[] = $row;
  60.     }
  61.  
  62.     print json_encode($output);
  63. }
  64.  
  65. get_matches_by_date();
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment