Hi I have tags in my database in a row called tags. They are separated by commas.
For example, they are stored in the database as tag1,tag2,tag3.
I want to retrieve them from the database and display them one by one separately and before displaying each tag, I want to link it to a URL.
Here’s what I am doing so far,
$keywords = strip_tags($blog_query_results['keywords']); //Retrives the tags from the database
echo wordwrap(stripslashes($keywords), 65, "<br>",true); // this prints tag1,tag2, and so on.
While printing them I want to link tag1, tag2, and tag3 to different URLS.
If you have a string like this :
You can use the
explode()function to get an array of tags :And, then, just iterate over that array, to build a link for each item — typically, using
foreach():As a sidenote : your database’s design is probably a bit wrong, if you store more than one information in a single field.
If you have 3 tags for a post, you should have 3 rows (one per tag), either :
tagstable,postsandtagstables.