Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Linking items in a string - and removing trailing comma


abbeyvet - 10:39 pm on Nov 16, 2008 (gmt 0)


I can do either, but not both together, and there must be a way!

I have created a tagging system, the tags are entered as a comma separated list, and I currently retrieve and display the tags like so:

$query = "SELECT pTags FROM tablename WHERE pID = whatever";
$result = mysql_query ($query);
$row = mysql_fetch_array($result);
$list = $row[0];
$tags = explode(',', $list);
foreach ($tags AS $tags)
{
echo "<a href=\"/tags.php?tag=$tags\">$tags</a>, ";
}

Which works fine, except of course I have a trailing comma and space.

I know I can print them out if I just needed the (unlinked) list using

$tags = substr($list, 0, -2);
echo $tags;

But how can I do both?


Thread source:: http://www.webmasterworld.com/php/3787521.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com