0

I am trying to generate a list of urls for the tags people who have submitted while posting their information. Data gets saved in mysql table as tags and the value comes with comma for multiple words,

for example: tag1, tag2, tag3 abd saved as is in a single field.

with explode function i am able to generate a single link with all commas as example.com/tag1, tag2, tag2.html

but what i need is with seperate url for comma seperated words as in

example.com/tag1.html
example.com/tag2.html
example.com/tag3.html

how can i achieve this? please help

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by veedeoo
0

Hi,

Try this script... I derived this from the tag cloud script I wrote when I was a newbie. This is my very first tag cloud script, and the very first time that I wrote a function.. The original script was pretty good. It almost took me forever trying and experimenting with arsort, ksort and many other stuffs related to array.

There you have it..

<?php
## define the the following
$db_host = "";
$db_user = "";
$db_password = "";
$db_database = "";

## endo of all definitions ##

mysql_connect($db_host, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());

function tag_info() { 
## change items  [ ] to your database table and column  .
  $result = mysql_query("SELECT * FROM [YOUR_TABLE ] GROUP BY [tags]  "); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['tags']] = $row['tags'];
  } 
  //ksort($arr); 
  return $arr; 
}

function tag_link() {

## define your domain here or the link url
$link_url = "home";
    $tags = tag_info();


    $tag_html = '';
    $cloud_tags = array();

    foreach ($tags as $tag) {
     
        $cloud_tags[] = '<a class="tag_link" href="'.$link_url.'/' . $tag.'.html" title="\'' . $tag  . '">'. htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $tag_html = join("\n", $cloud_tags) . "\n";
    return $tag_html;

}

print tag_link();
?>

Edited by veedeoo: n/a

0

holli macaroni! :).. I forgot the explode function..

jUst place these codes where appropriate.

$tags = explode(',', $row['tags']) ;

remove the , and then trim

$tags = trim(str_replace(",", "", $tags)) ;
0

here is the demo using the same script as above. The only difference is that the demo is going to someDomainDot/search/tags.. Which is pretty similar to what you are looking for. By the way.. , the demo is the old version of my open source re-release version of vidiscript youtube clone script..My latest release is way much better than that...

Edited by veedeoo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.