2012-07-18 15 views
0

值在3表中插入如何獲取由MySQL和PHP的結果,如果object_id是相同

表1:wp_terms

enter image description here

表2:wp_term_taxonomy

enter image description here

表3:wp_term_relationships

enter image description here

我需要輸出中像這樣(我想獲取基於類別的所有品牌和設計師)

enter image description here

我已經試過這

$sql="select term_taxonomy_id from wp_term_taxonomy where term_id=177"; 
mysql_query($sql); 

我得到了輸出251

但我被困在表3:wp_term_relationships如何獲取其中object_id有類似的數據:550,540(對於類別,樂隊,設計師)

回答

0

我想查詢SHD這個樣子的:

SELECT m.name, t.taxanomy, t.description from wp_term_relationships r 
INNER JOIN wp_term_taxonomy t on r.term_taxonomy_id = t.term_taxonomy_id 
INNER JOIN wp_terms m on m.term_id=t.term_id 
WHERE (r.object_id=550 or r.object_id=540) and t.term_id=177 
+0

感謝您的回覆,我嘗試過 – 2012-07-18 07:04:05

+0

我運行該查詢,但我只拿到類別不是品牌和設計師 – 2012-07-18 07:12:08

+0

哪個表存儲品牌和設計師?我有點困惑。如果你可以用一些有意義的數據填充表格會更好,這樣更容易理解。 – sel 2012-07-18 07:27:00

相關問題