Jump to content

PHP category list


iRoot121
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hai guys, I'm busy with a category display script, but do I replace the text for an URL?

 

Example:

I've this code at the moment:

<?php
$query="SELECT `cat` FROM `video` WHERE `id`='".$_GET['video']."'";
$sql=mysql_query($query) or die(mysql_error());
while($line=mysql_fetch_array($sql))
{
    echo ''.$line['cat'].'';
}
?>

The output for example is: Category1,Category2,Category3.

 

So, what do I need to let the output be like this: <a href="category.php?cat=Category1">Category1</a>, <a href="category.php?cat=Category2">Category2</a>, <a href="category.php?cat=Category3">Category3</a>

 

Thanks for any help! :)

Edited by iRoot121
Link to comment
Share on other sites

  • Solution

Oh didn't read your post properly. I though $row['cat'] echos a category each time.

$categoroes = explode(',', $line['cat']);
foreach($categories as $k => $category)
{
    $categories[$k] = '<a href="category.php?id='.$category.'">'.$category.'</a>';
}
echo implode(', ', $categories);
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.