dsm13698679318 2014-02-01 02:32
浏览 80
已采纳

php sql查询没有返回正确的结果

I have a page with 3 dropdowns. Team1, Team2 & Venue

enter image description here

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:

enter image description here

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

  • 写回答

2条回答 默认 最新

  • dsq30861 2014-02-01 02:34
    关注

    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 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗