I want to retrieve some tags from my database, they are in the form:
topic_id tags
1 `tag1,tag2,tag3`
2 `tag1,tag4,tag5`
3 `tag2,tag4,tag5`
4 `tag6,tag7,tag2`
I want to have something like this:
tag1 tag2 tag3 tag4 tag5 tag6 tag7
i.e all unique tags
So that I can wrap each tag in a link in order to group news articles that has such specific tags.
This following query I've written so far is not working:
$tags = mysql_query("SELECT tags, topic_id
FROM forum_topics
WHERE topic_id > 0") or die (mysql_error());
while($tag = mysql_fetch_assoc($tags)){
$split_tags = "$tag";
$pieces = explode(",", $split_tags);
echo $pieces ;
When I did print_r($pieces);
I got Array ( [0] => Array ) Array ( [0] => Array ) Array ( [0] => Array ) Array ( [0] => Array )
Which was not what I was looking for.
As it is now my table structure looks like this topic_id , topic_head, topic_body, topic_tag, topic_date, topic_owner
.. How can I further make the topic_tag normal.
select distinct tags from forum_topics
query to get what you want. – Shannashannahmysql_*
functions in your code. These functions are no longer maintained and are being deprecated. Instead, you should use either MySQLi or PDO. Don't know which to use? This article should help. – Shannashannah