Lyleyboy Posted July 17, 2007 Share Posted July 17, 2007 Hi all, I am doing a league table script for a project but I cant make it do one thing I would really like. I hope there is a way. If have two team names coming in from a form. $team1 & $team2. Basically these are entered by the users by way of saying "I want to see the fully history of these two teams" But my table has two fields home_team & away_team My query at the moment is $sql="SELECT * FROM user WHERE home_team='$team1' and away_team='$team2'"; This is fine but it only returns half the records I want. What I need is to say $sql="SELECT * FROM user WHERE home_team='$team1' OR '$team2" and away_team='$team2' OR '$team1""; I hope that made sense. Please give me a shout Link to comment https://forums.phpfreaks.com/topic/60342-or-statement-in-query/ Share on other sites More sharing options...
Illusion Posted July 17, 2007 Share Posted July 17, 2007 SELECT * FROM user WHERE home_team='$team1' OR '$team2' UNION SELECT * FROM user WHERE away_team='$team1' OR '$team2' Link to comment https://forums.phpfreaks.com/topic/60342-or-statement-in-query/#findComment-300210 Share on other sites More sharing options...
Lyleyboy Posted July 17, 2007 Author Share Posted July 17, 2007 Cool, I will give that a whirl. Does the UNION act as an "and" the or just join two queries? Link to comment https://forums.phpfreaks.com/topic/60342-or-statement-in-query/#findComment-300226 Share on other sites More sharing options...
Illusion Posted July 17, 2007 Share Posted July 17, 2007 just combines and display the records returned from the second query to the first one records. Link to comment https://forums.phpfreaks.com/topic/60342-or-statement-in-query/#findComment-300250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.