★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/001898.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  echo and commas

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   echo and commas
zcrar70
Member
posted July 13, 2000 10:34 AM     Click Here to See the Profile for zcrar70   Click Here to Email zcrar70     Edit/Delete Message Reply w/Quote
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

SepodatiCreations
Member
posted July 13, 2000 09:11 PM     Click Here to See the Profile for SepodatiCreations   Click Here to Email SepodatiCreations     Edit/Delete Message Reply w/Quote
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...

zcrar70
Member
posted July 14, 2000 06:01 AM     Click Here to See the Profile for zcrar70   Click Here to Email zcrar70     Edit/Delete Message Reply w/Quote
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

SepodatiCreations
Member
posted July 14, 2000 06:24 AM     Click Here to See the Profile for SepodatiCreations   Click Here to Email SepodatiCreations     Edit/Delete Message Reply w/Quote
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...

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.