Jump to content

PHP category list


iRoot121

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! :)

Link to comment
https://forums.phpfreaks.com/topic/283199-php-category-list/
Share on other sites

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
https://forums.phpfreaks.com/topic/283199-php-category-list/#findComment-1455008
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.