php多表聯查??
我有2個表
A表: B表:
id title id content
1 a1 a1 內容1
2 a2 a2 內容2
3 a3 a3 內容3
現在我需要根據A表裡的title顯示3條B表裡的content, 也就是大家常說的把分類和內容分表放, 但是取得時候怎麼根據A表裡的title取得B表的內容。
我要顯示3條A表title 但是還要對應B表的content, 分表從來沒瞭解過, 這次大家就來教育教育我吧
------最佳解決方案--------------------
本帖最後由 xuzuning 於 2012-11-09 08:48:42 編輯 select a.id, a.title, b.content from A表 a, B表 b where a.id=b.id limit 3
------其他解決方案--------------------
select A.id, A.title, B.content from A inner join B b on A.title=B.id
------其他解決方案--------------------
網上很多例子
------其他解決方案--------------------
left join in
------其他解決方案--------------------
回複樓上朋友們:
……
剛醒來, 就來看文章, 試了下版主和jordan102的方法 只能得到A表的東西, 或許是我沒用對, 還請麻煩你們寫出那一小段代碼 就是寫到while迴圈顯示的地方。 我再補充下我的問題吧, 沒描述好
A表:
------其他解決方案--------------------
B表:
id title sex
------其他解決方案--------------------
id content age ……
1 小易 男
------其他解決方案--------------------
小明 學生 18 ……
2 小明 男