Skip to main content
Inspiring
August 20, 2010
Question

auto generate team matches

  • August 20, 2010
  • 1 reply
  • 422 views

Hi,

I need to auto generate matches for football teams where the each football team is matched up with another to play a game.

Each team places another team twice.

So Match set 1 and Match Set 2

Match set one is at "home" and Match set two is "away"

I am not sure how to get this done so it will hold the information on the matches.

This topic has been closed for replies.

1 reply

Inspiring
August 23, 2010

Ok,

I have this, but it only outputs 1 teams twice.

$query_match_fixtures = "select m.match_id, m.date, m.time, m.report, t1.team_name, s1.score, t2.team_name, s2.score from matches m left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id) where s1.team <> s2.team group by match_id order by m.match_id";

-- Table structure for table `matches`
--

CREATE TABLE IF NOT EXISTS `matches` (
  `match_id` int(8) NOT NULL auto_increment,
  `date` date default NULL,
  `time` varchar(5) default NULL,
  `report` longtext,
  `referee_id` int(8) NOT NULL,
  `season_id` int(8) NOT NULL,
  `venue_id` int(8) NOT NULL,
  PRIMARY KEY  (`match_id`),
  KEY `referee_id` (`referee_id`),
  KEY `venue_id` (`venue_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

-- Table structure for table `matchscores`
--

CREATE TABLE IF NOT EXISTS `matchscores` (
  `matchscores_id` int(8) NOT NULL auto_increment,
  `match_id` int(8) NOT NULL,
  `team` int(8) NOT NULL,
  `score` int(8) default NULL,
  PRIMARY KEY  (`matchscores_id`),
  KEY `match_id` (`match_id`,`team`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;