Variable in SQL Query
Posted: Tue Apr 06, 2010 9:21 pm
I am trying to add a variable $date to my SQl query and its screwing up somewhere. It works if I use Current_Date( ), but I need to run functions on the date. I'm pretty sure it's the quotes somewhere. Can anyone help? Thanks.
$result = mysql_query('SELECT h.TeamAffiliate AS AwayTeam , a.TeamAffiliate AS HomeTeam , g.HomeTeamID , g.AwayTeamID ,
g.GameDate , g.GameLocation , g.GameTime '
. ' FROM MLBGameTable g '
. ' INNER JOIN TeamsTable h '
. ' ON g.HomeTeamID = h.TeamID '
. ' INNER JOIN TeamsTable a '
. ' ON g.AwayTeamID = a.TeamID '
. ' WHERE GameDate = $date '
. ' ORDER BY GameTime LIMIT 0, 30 ');
$result = mysql_query('SELECT h.TeamAffiliate AS AwayTeam , a.TeamAffiliate AS HomeTeam , g.HomeTeamID , g.AwayTeamID ,
g.GameDate , g.GameLocation , g.GameTime '
. ' FROM MLBGameTable g '
. ' INNER JOIN TeamsTable h '
. ' ON g.HomeTeamID = h.TeamID '
. ' INNER JOIN TeamsTable a '
. ' ON g.AwayTeamID = a.TeamID '
. ' WHERE GameDate = $date '
. ' ORDER BY GameTime LIMIT 0, 30 ');