2016-08-13 53 views
0

我有3個表:加入3臺配有獨立的where子句

USERS(id, username, email, password) 

QUESTIONS(id, uid, type, ques, date, time) 

ANSWERS(id, a_uid, qid, reply, a_date, a_time) 

我想SELECT * FROM所有三個表

where $_SESSION[‘id’] = questions.uid 

& users.id = questions.uid 

& questions.id = answers.qid 

我怎樣才能做到這一點?

+0

請提高與[編輯]這個問題 – Drew

回答

0
select * 
from USERS 
inner join QUESTIONS on users.id = questions.userid 
inner join ANSWERS on questions.id = answers.qid 
where questions.uid = $_SESSION['id'] ; 
+0

我得到這個錯誤:解析錯誤:語法錯誤,意想不到 ''(T_ENCAPSED_AND_WHITESPACE),在期待標識符(T_STRING)或可變(T_VARIABLE)或數字(T_NUM_STRING) C:\ xampp \ htdocs \ trying \ notification.php在線86 –

+0

解決!感謝.... –

0

您可以使用SQL joins來指定您的where子句。

select * 
from USERS U 
join QUESTIONS Q on U.id = Q.uid 
join ANSWERS A on Q.id = A.qid 
where $_SESSION['id'] = Q.uid ; 
+0

我得到此錯誤:解析錯誤:語法錯誤,意外的''(T_ENCAPSED_AND_WHITESPACE),期待標識符(T_STRING)或變量(T_VARIABLE)或數字(T_NUM_STRING)在C:\ xampp \ htdocs \ try \ notification 86線上的.php –

+0

已解決,..... thanxxxxx –