简体   繁体   中英

How to fetch result by MySql and Php if object_id is same

Values inserting in 3 table

Table1: wp_terms

在此处输入图片说明

Table2: wp_term_taxonomy

在此处输入图片说明

Table3: wp_term_relationships

在此处输入图片说明

I need ouput like this(i want fetch all brand and designer based on category)

在此处输入图片说明

I have tried this

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

I got output 251

But I am stuck in Table3: wp_term_relationships on how to fetch data where object_id are similar: 550, 540(for category, band, designer )

I guess the query shd look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM