Select all tags separated by "," from every table

Asked

Viewed 39 times

0

id | tags
1  | tag1,tag2,tag3
2  | tag1,tag2,tag3

In db there is the column "tags" where is "tag1,tag2,tag3..." need to show all separate tags, however shows only the first record, I would like to get the tags of all, as I do?

 $tags =  explode(',', $tags_row);

 foreach ($tags as $item) { 
   echo "< href='#'>$item</a> "; 
 }

1 answer

2

There are several ways to solve the problem, follow an example:

$tags_row = 'tag1, tag2, tag3';

$tags =  explode(',', $tags_row);

foreach ($tags as $item) { 
 echo "<href='#'>{$item}</a><br>"; 
}

its logic is correct, to print PHP variables using quotation marks "" dupulas in echo should use {$variavel} for php to escape the quotation marks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.