Okay I have a query that looks like this :
"SELECT `tag_name`,`sub_tag_name` FROM phpro_tag_targets targets
INNER JOIN sub_tags ON targets.sub_tag_id=sub_tags.sub_tag_id
INNER JOIN phpro_tags tags ON targets.tag_id=tags.tag_id
WHERE tag_target_id='{$vid['tag_target_id']}'";
The tables themselves looks like this:
phpro_tag_targets:
tag_target_id | tag_id | sub_tag_id | tag_target_name | tag_type_id
int(11) | int(11) | int(11) | var_char | int(3)
<PK - index> | <fk> | <fk>
phpro_tags:
tag_id | tag_name
<PK> | VARCHAR
sub_tags:
sub_tag_id | sub_tag_name
<PK> | VARCHAR
and the result of the query looks something like this
Array (
[0] => Array ( [tag_name] => Humanity [sub_tag_name] => Children )
[1] => Array ( [tag_name] => Society [sub_tag_name] => Children )
[2] => Array ( [tag_name] => Art and Artists [sub_tag_name] => Creativity )
[3] => Array ( [tag_name] => Humanity [sub_tag_name] => Creativity )
[4] => Array ( [tag_name] => Humanity [sub_tag_name] => Culture )
[5] => Array ( [tag_name] => Society [sub_tag_name] => Culture )
[6] => Array ( [tag_name] => unlisted [sub_tag_name] => Culture )
[7] => Array ( [tag_name] => unlisted [sub_tag_name] => Culture )
)
The result is the tags and subtags associated with a piece of content (ie. video or article). I am attempting to display this information in html such that I have a <span class="tags">
and a <span class="subtags">
. For the above eg. data the html would look like this:
<span class="tags"> Humanity Society Art and Artists unlisted </span>
<span class=subtags> Children Creativity Culture </span>
Is there a way that I can somehow filter data using php (or altering the query) so that I am only displaying Each different value a single time. As I am currently using a loop to cycle through the dat and displaying the same tag, and subtags multiple times, but can't figure out how to further filter the result.
An insight into how I could do this would be greatly appreciated!