2016-05-12 168 views
-1

查询数据我有三个表:约束,车站和时间PHP - 似乎无法从表

界有2列:boundID和boundName

站有3列:的stationID工作站名称boundID

时间有4列:timeID departureTime tramID stationID

我正在使用此查询来获取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"; 
    } 

感谢

+0

'和b.boundName'这不是条件; – itzmukeshy7

回答

0

和b.boundName不应该出现,因为一个WHERE条件计算为1或0所以个人陈述也应该这样做,在你的陈述中肯定不会返回0或1。

1

你必须删除最后一个: '和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"; 
0

如果使用加入试试这个

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`);