Jump to content

Implode failing, but why?


jfulbrook

Recommended Posts

Hello there,

 

I am using an 'Implode' to separete my array with commas. Pretty standard I thought, but if fails every time, but why, I don't know? Any suggestions would be greatfully recieved, please see code below:

 

 
$row_getJournalAuthors = mysql_fetch_array($query_getJournalAuthors);
$arr = array($row_getJournalAuthors['name']);
$str = implode(", ",$arr);
echo $str;

 

The result is just the names, but no commas or spaces; like this - John SmithJoe BloggsBurt Reynolds

 

Any clues anyone?

 

Thanks in advance!!

Link to comment
Share on other sites

It's because implode() takes an array and separates each element and makes a string using the first parameter as a delimiter. In your code $arr only contains one element( $row_getJournalAuthors['name'] ), so nothing is actually done. Can you show us an example of what $row_getJournalAuthors['name'] contains?

Link to comment
Share on other sites

Hello,

 

Thanks for the response so far.

 

The data for $row_getJournalAuthors['name'] is a first and second name in one field. i.e. John Smith.

The other field is an author ID.

 

When i use a for each loop like this:

 

$row_getJournalAuthors = mysql_fetch_array($query_getJournalAuthors);
foreach($row_getJournalAuthors as $author){
   $arr[] = $author;}
$str = implode(", ",$arr);
echo $str;

 

I get:

 

144, 144, Paul smith, Paul smith, 1, 1144, 144, Paul smith, Paul smith, 1, 1, 147, 147, Lynne marks, Lynne marks, 1, 1

 

Please note there is a While loop going on behind the for each loop

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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