Folks,
I am relatively new to php but i am learning slowly. I am building a sports database website / cms, which is getting there very nicely.
I am having an issue joining 3 tables together, if i use then as seperate queries they do 'exactly' what i want then to do, however i am at a loss as to how to join them together.
As far as i am aware i do not need to change anything in the database itself i just need to get the query correct.
The following select queries work perfectly seperately: -
Query 1
$get_players = mysql_query("
SELECT P.PlayerID AS id,
P.PlayerLastName AS lastname,
P.PlayerFirstName AS firstname,
P.PlayerPublish,
P.PlayerNumber AS number
FROM idihc_seasons S
LEFT OUTER JOIN idihc_players P ON P.PlayerID = S.SeasonPlayerID
WHERE seasonid = 5 and P.PlayerPublish = 1
GROUP BY id
ORDER BY number
",$connection)
or die(mysql_error());
Query 2
$get_players = mysql_query("
SELECT *
FROM idihc_seasonnames
WHERE SeasonPublish = 1
",$connection)
or die(mysql_error());
In query 1 i would like
'WHERE seasonid = 5' to be
'WHERE SeasonPublish = 1' from query 2.
These are the follow tables from the database: -
`idihc_players` (
`PlayerID` int(10) unsigned NOT NULL auto_increment,
`PlayerFirstName` varchar(32) NOT NULL default '',
`PlayerLastName` varchar(64) NOT NULL default '',
`PlayerNumber` tinyint(3) unsigned NOT NULL default '0',
`PlayerPublish` tinyint(1) unsigned NOT NULL default '1',
PRIMARY KEY (`PlayerID`)
`idihc_seasons` (
`SeasonID` int(10) unsigned NOT NULL default '0',
`SeasonPlayerID` int(10) unsigned NOT NULL default '0',
KEY `SeasonID` (`SeasonID`),
KEY `SeasonPlayerID` (`SeasonPlayerID`)
`idihc_seasonnames` (
`SeasonID` int(10) unsigned NOT NULL auto_increment,
`SeasonName` varchar(64) NOT NULL default '',
`SeasonPublish` tinyint(1) unsigned NOT NULL default '1',
PRIMARY KEY (`SeasonID`)
The database works exactly how i want it to in the CMS so i would rather not be changing it at this stage.
I am trying to only display the players that are in a season that is published.
I hope all this makes sense, and look forward to any help you can offer.
Steve