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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记