无法使用php

时间:2015-12-10 07:22:54

标签: php database

我有一段非常简单的代码,我无法工作。我只是想在这三个表中搜索这些值。当我删除它的第二个两个Select语句时,无论我从哪个表中选择它都有效。它与UNION语句有关。谢谢

$query =    "SELECT First_Name, Last_Name, yards FROM quarterbacks WHERE  Nickname='$nickname' AND Last_Name='$last_name'
            UNION 
            SELECT First_Name, Last_Name, yards FROM runningbacks WHERE Nickname='$nickname' AND Last_Name='$last_name'
            UNION 
            SELECT First_Name, Last_Name, yards FROM recievers WHERE Nickname='$nickname' AND Last_Name='$last_name'";

$result =mysqli_query($db, $query) or die('error getting data');

2 个答案:

答案 0 :(得分:0)

试试这个

$query= "SELECT  quarterbacks.First_Name AS a, quarterbacks.Last_Name AS b, quarterbacks.yards AS c, runningbacks.First_Name AS p, runningbacks.Last_Name AS q, runningbacks.yards AS r, recievers.First_Name AS x, recievers.Last_Name AS y, recievers.yards AS z 
        FROM  quarterbacks, runningbacks, recievers 
        WHERE Nickname='$nickname' AND Last_Name='$last_name'";

答案 1 :(得分:-1)

我认为你错过了单引号

    SELECT First_Name, Last_Name, yards FROM quarterbacks WHERE       
Nickname='$nickname' AND Last_Name='$last_name

SELECT First_Name, Last_Name, yards FROM quarterbacks WHERE Nickname='$nickname' AND Last_Name='$last_name' -<<<<<<