Help with tags for PHP site.

Discussion in 'PHP' started by ChristopherLeeMaher.Com, May 11, 2011.

  1. #1
    Hello,

    In my database I have tags for items but i need it to turn
    tag0, tag1, tag2, tag3, tag4, tag5, tag6
    HTML:
    into
    <a href="/tag/tag0">tag0</a>, <a href="/tag/tag1">tag2</a>, <a href="/tag/tag3">tag3</a>, <a href="/tag/tag4">tag4</a>, <a href="/tag/tag5">tag5</a>
    HTML:
     
    ChristopherLeeMaher.Com, May 11, 2011 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    It shouldnt be too hard to do that, no tested this, you might have to fiddle with it a little bit

    <?php
    # first of all select your tags from your database - you havent given your table structure so this part is up to you
    $sql = "SELECT tag from yourtagstable";
    $query = mysql_query($sql);
    
    $count = 0;
    
    while ($result = mysql_fetch_assoc($query))
    	{
    	$count++;
    	print "<a href=\"/tag/{$result['tag']}\">{$result['tag']}</a>";
    	if($count != mysql_num_rows($query)) print ", ";
    	}
    ?>
    PHP:
     
    lukeg32, May 12, 2011 IP
  3. LiftBigEatBig

    LiftBigEatBig Well-Known Member

    Messages:
    302
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    123
    #3
    LiftBigEatBig, May 15, 2011 IP