I have four tables that are related.
images Table
cid link
=======================
1 something.jpg
2 else.jpg
terms Table
cid term is_attr
1 Location 0
2 Caption 1
3 Camera Lens 0
tags Table
cid Name term_id
1 somewhere 1
2 BFE 1
3 A word 2
linked_tags Table
cid photo_id tag_id
1 1 1
2 1 2
3 1 3
if the term is_attr == 1for this term should have only one entry in the table linked_tags.
If I were to query the image table and get the tags at the same time, how would I do it?
I would like to return (something):
_____________________________________________________________________________
cid |link |attributes |tags |
=========|==================|==================|====================|
1 |something.jpg |__________________|____________________|
| ||term |value |||term |value ||
| ||========|=======|||========|=========||
| ||caption |A word |||Location|somewhere||
| || | |||Location|BFE ||
This is what I am looking for (PHP side):
array(
'link' => "something.jpg",
'attributes' => array('caption'=>"A word"),
'tags' => array('Location'=>array('somewhere','BFE'))
);
array(
'link' => "else.jpg",
'attributes' => array(),
'tags' => array()
);
array(
'link' => "else.jpg"
);
array(
'link' => "else.jpg",
'attributes' => array('caption'=>""),
'tags' => array();
);
Jason source
share