I have once again returned to seek the guidance of you awesome guru's.
I came here before wanting help with this query and I learned that my table design was all wrong. I have since changed the table design and re-worked most of the queries I had. It works great to BTW. However I have found myself in the same place I was before when I first came to this site.
I manage a fantasy football league and on our website I would like to be able for team owners to:
use a drop down list to choose a team name (usually there own, but can be any) then hit the select button
COMPLETE
the new page should bring up a list of all the active teams in the league and the chosen teams record against each, with the results of the last time they played each other.
Example:
Chosen team are the Green Bay Packers
6-2 against the Chicago Bears
Last time played Week 2 of 2011
Result: Chicago Bears won 21-17
2-5 against the Cleveland Browns
Last time played Week 16 of 2010
Result: Green Bay Packers won 14-3
3-4 against the Seattle Seahawks
Last time played Week 7 of 2011
Result: Green Bay Packers won 10-0
etc
etc
I have had no success in even getting close to this format.
the three tables that matter are:
CREATE TABLE `game_setup` (
`game_id` INT(10) NOT NULL AUTO_INCREMENT,
`week` VARCHAR(7) NOT NULL,
`year` YEAR(4) NOT NULL,
`home_id` INT(4) NOT NULL,
`game_type` ENUM('Normal','Playoff','Super Bowl') NOT NULL DEFAULT 'Normal',
PRIMARY KEY (`game_id`),
INDEX `FK_game_setup_week` (`week`),
INDEX `FK_game_setup_year` (`year`),
INDEX `FK_game_setup_owners` (`home_id`),
CONSTRAINT `FK_game_setup_owners` FOREIGN KEY (`home_id`) REFERENCES `owners` (`owner_id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_game_setup_week` FOREIGN KEY (`week`) REFERENCES `week` (`week`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_game_setup_year` FOREIGN KEY (`year`) REFERENCES `year` (`year`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=609;
I know, I know I am bad when it comes to the dates, but in this rare case this format actually works the way I need things to happen.
CREATE TABLE `game_scores` (
`team_id` INT(10) NOT NULL,
`game_id` INT(10) NOT NULL,
`score` FLOAT(12,1) NULL DEFAULT NULL,
PRIMARY KEY (`team_id`, `game_id`),
INDEX `FK_game_scores_game_setup` (`game_id`),
CONSTRAINT `FK_game_scores_game_setup` FOREIGN KEY (`game_id`) REFERENCES `game_setup` (`game_id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_game_scores_owners` FOREIGN KEY (`team_id`) REFERENCES `owners` (`owner_id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
CREATE TABLE `owners` (
`owner_id` INT(4) NOT NULL AUTO_INCREMENT,
`teamname` VARCHAR(50) NOT NULL,
`active` INT(1) NOT NULL DEFAULT '0' COMMENT '0 = not active, 1 = active, 2 = not active but coming, -1= racing, -2= NCAA',
`firstname` VARCHAR(20) NOT NULL,
`date_joined` DATE NOT NULL,
`rookie` VARCHAR(25) NOT NULL,
`division` VARCHAR(15) NOT NULL,
`profile` TEXT NOT NULL,
INDEX `teamname` (`teamname`),
CONSTRAINT `owners_ibfk_1` FOREIGN KEY (`division`) REFERENCES `divisions` (`division`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=42;
As always thank you very much for any help given.