This may be a bit of a no-brainer so my apologies in advance
I am trying to separate the items in a array with commas. Straight forward enough, except I am trying make it not have a comma on the last item.
To clarify, I am trying to do this:
item, item, item
but am getting
item, item, item,
The script I am using is:
Now, this SHOULD work, but for the life of me, I cannot figure out why it doesn't.
I may not be seeing the would for the trees here. I would be grateful for any advice.
Thanks for reading.
I am trying to separate the items in a array with commas. Straight forward enough, except I am trying make it not have a comma on the last item.
To clarify, I am trying to do this:
item, item, item
but am getting
item, item, item,
The script I am using is:
Code:
while($i = mysql_fetch_array($result))
{
$subcategory=$i["subcategory"];
$string="";
for ($i=0; $i<count($subcategory); $i++)
{
$string.= $subcategory;
if ($i == count($subcategory)-1)
{
$string.=", ";
}
else
{
$string.= "";
}
}
echo $string;
}
Now, this SHOULD work, but for the life of me, I cannot figure out why it doesn't.
I may not be seeing the would for the trees here. I would be grateful for any advice.
Thanks for reading.