php - how can i print all Items with x tag -


i have 3 related table in mysql, this:

table: items columns: id, item_id, item_title, content  table: tags columns: tag_id, tag_title  table: items_tags columns: item_id, tag_id 
  • item_id foreign key in items table.

  • items_tags correlation table.

now want print items x tag.

for example:

// items +-----+-----+---------+-----------------+ |  1  | 123 |  tile1  |    content1     | ----------------------------------------- |  2  | 123 |  tile2  |    content2     | ----------------------------------------- |  3  | 444 |  tile3  |    content3     | ----------------------------------------- |  4  | 333 |  tile4  |    content4     | -----------------------------------------  // tags +------+-----+ |  22  | php | -------------- |  23  | js  | -------------- |  11  | sql | --------------  // item_tags +-------+-----+ |  123  | 22  | --------------- |  444  | 23  | --------------- |  333  | 11  | --------------- 

i not know why i'm confused, know should use join, how ?! how can print items php tag ?

you need join tables , search tag title needed.

select * items  left join item_tags on i.item_id = it.item_id left join tags t on t.tag_id = it.tag_id tag_title = 'x' 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -