Reputation: 1598
I have a page with 3 dropdowns. Team1, Team2 & Venue
When the user clicks view, I then query the DB returning results for team1 against team2 either playing at home or away or both (depending on users selection)
The code Im using to execute the query follows
if($venue = "hometeam"){
$result= " SELECT *
FROM `results`
WHERE `hometeam` = '$team1' && `awayteam` = '$team2'" or die(mysql_error());
}
else if($venue = "awayteam"){
$result = " SELECT *
FROM `results`
WHERE `awayteam` = '$team1' && `hometeam` = '$team2'"or die(mysql_error());
}
else if($venue ="all"){
$result = " SELECT *
FROM `results`
WHERE (`hometeam` = '$team1' AND `awayteam` = '$team1') OR (`hometeam` = '$team2' AND `awayteam` = '$team2')"or die(mysql_error());
}
The Problem
Regardless if the user selects venue away or both home & away the result returned is always team1 as the hometeam as you can see in the image below:
In the above example I selected Team1 as Stormers and Team2 as Sharks, I selected venue away to display Stormers record against Sharks when they are playing away from home, but as you can see from the image Stormers still gets displayed as the hometeam.
If anyone can tell me what I am doing wrong or point me in the right direction it would be greatly appreciated.
Thank you in advance
Upvotes: 2
Views: 128
Reputation: 74232
You're currently "assigning" instead of "comparing" with your conditional statements. It being in the "plural" form. You have three which should be ==
instead of =
=
is an assignment operator, while ==
is a comparison operator.
Missing an extra =
see arrows ^
if($venue = "hometeam")
^
else if($venue = "awayteam")
^
else if($venue = "all")
^
Rewrite:
if($venue == "hometeam"){
$result= " SELECT *
FROM `results`
WHERE `hometeam` = '$team1' && `awayteam` = '$team2'" or die(mysql_error());
}
else if($venue == "awayteam"){
$result = " SELECT *
FROM `results`
WHERE `awayteam` = '$team1' && `hometeam` = '$team2'"or die(mysql_error());
}
else if($venue == "all"){
$result = " SELECT *
FROM `results`
WHERE (`hometeam` = '$team1' AND `awayteam` = '$team1') OR (`hometeam` = '$team2' AND `awayteam` = '$team2')"or die(mysql_error());
}
Upvotes: 1
Reputation: 68556
You are doing an assignment operation on your if
statements. Make use of ==
instead of =
The
if($venue = "hometeam"){
should be
if($venue == "hometeam"){
//^------ Add one more like this. Do this for your `elseif` too
Upvotes: 2