Jump to content

display tags one by one


php_begins

Recommended Posts

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.

I know we can use php explode function. But i m not sure how to go about it.

Link to comment
Share on other sites

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,tag3 to different URLS.

Thanks.

 

Link to comment
Share on other sites

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,tag3 to different URLS.

 

Ok, but where are you getting those URLs and how are you going to associate them with the correct tag? Here's some code to output the tags as links, but it just uses a hard-coded URL because I have no idea where you are getting them from.

 

//Explode the DB result into an array using the commas
$keywordsArray = explode(',', $blog_query_results['keywords']);
//Iterate through each keyword
foreach($keywordsArray as $keywordString)
{
    //Parse the tag value. Don't know the purposes of stripslashes and strip_tags, but I left them in
    // - I would think htmlenteties woud be a better option
    $label = stripslashes(strip_tags(trim($keywordString)));
    //Get URL for the tag. You didn't provide any details, so this is just hard-coded
    $url = "http://www.yahoo.com";
    //Output the final link
    echo "<a href=\"{$url}\">{$label}</a><br>\n";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.