PHP-可以';似乎无法从表中查询数据


PHP - can't seem to query data from table

我有三个表:界、站和时间

Bound有2列:boundID和boundName

Station有3列:stationID stationName boundID

时间有4列:时间ID部门时间电车ID车站ID

我正在使用此查询来获取boundName,但似乎无法获取数据。任何帮助都将不胜感激!

    $query ="SELECT b.boundName, s.stationName, t.departureTime 
    from Station s, Time t, Bound b 
    where s.stationID = t.stationID 
    AND t.departureTime !=''
    AND s.boundID = b.boundID
    AND b.boundName";  
    }

感谢

您必须删除最后一个:"AND b.boundName".

使用此:

$query ="SELECT bound.boundName FROM bound, station, time WHERE
station.stationID = time.stationID AND time.departureTime !='' AND 
station.boundID = bound.boundID";

或者这个:

$query ="SELECT b.boundName, s.stationName, t.departureTime 
    from Station s, Time t, Bound b 
    where s.stationID = t.stationID 
    AND t.departureTime !=''
    AND s.boundID = b.boundID";
结尾的AND b.boundName不应该存在,因为WHERE条件的计算结果为1或0,因此单个语句也应该这样做,这在语句中肯定不会返回0或1。

如果您使用join,请尝试此

    SELECT
    `time`.`departureTime`
    , `station`.`stationName`
    , `bound`.`boundName`
FROM
    `test`.`station`
    LEFT JOIN `test`.`bound` 
        ON (`station`.`boundID` = `bound`.`boundID`)
    LEFT JOIN `test`.`time` 
        ON (`time`.`stationID` = `station`.`stationID`);