July 13th, 2000, 11:34 AM
-
hi,
another slightly stupid question that i'm not sure how to fix: I am writing a metatag generator, for which i get the info from a database. The code is:
$brandmetatag = new DBconnect;
$query = "select item_name from dbtable where item_name like '%'";
$brandmetatag-> dbquery($query);
while ($brandmetatag->next_record()):
$i = 0;
$j = sizeof($brandmetatag->Record);
while ($i < $j) {
echo $brandmetatag->Record[$i], ", ";
$i++;}
endwhile;
For some reason, I always get two commas in a row printed out after each Record. When I leave a space this comes out fine, as does leaving no separation. Any ideas why this is or how to get around it ?
cheers,
-nick
July 13th, 2000, 10:11 PM
-
not sure if this is the problem, but php uses a period to join strings together. it looked like you were trying to use a comma i.e. javascript.
echo "Hello" . " World";
echo $brandmetatag->Record[$i] . ", ";
---John Holmes...
July 14th, 2000, 07:01 AM
-
unfortunately that musn't be it, cos i stil get the same result, namely two commas in a row separated by a space. Actually according to the php manual i think you can use the comma with echo to print a series of things, as in:
echo "foo", $bar;
but anyways, does anyone know how to get rid of this ? Could it be a bug or something ? Although apparently finding bugs is quite unlikely....
-nick
July 14th, 2000, 07:24 AM
-
Are you just tring to join all of the array elements into a comma seperated string? how about using implode? one command will join the entire array for you.
$string = implode(", ",$array);
if you needed to get your array back, you could use
explode(", ",$string);
it seems like this would be easier than going through a loop and joining them...
---John Holmes...