mysql php implode row for links?
Not sure if there a way of doing this, but I can insert multiple categories into MYSQL, using :
GetSQLValueString(implode($_POST['r_category'],", "), "text"),
So then when I echo:
<?php echo $row_Recordset1['r_category']; ?>
It is fine, like this: Cat 1, Cat 2, Cat 3
I am trying to find a way to link each category for easy navigation purposes!!
Like this:
<a href="/page/results.php?r_category=<?php echo $row_Recordset1['r_category']; ?>"><?php echo $row_Recordset1['r_category']; ?></a>
This works great for One开发者_开发知识库 Cat, but if I have multiple Cats, then it is one big link.... not what I want.
I need to use implode or explode, but not sure how ? Thanks in advance!!!
This is what I would love:
Cat 1, Cat 2, Cat 3 (these are all separated links pulling from one row!)
If $row_Recordset1['r_category'] is the string "Cat 1, Cat 2, Cat 3", then you can explode that into an array like this:
$arr = explode(",", $row_Recordset1['r_category']);
then step through your array to create the links:
$links = array();
foreach ($arr as $value)
{
$links[] = "<a href='/page/results.php?r_category=". trim($value) ."'>". trim($value) ."</a>";
}
$links_str = implode(", ", $links);
echo $links_str;
精彩评论