Jump to content

[SOLVED] implode function


timmah1

Recommended Posts

I'm setting up a newsletter system.

 

I have a form that selects everybody from the database and puts the users email address into a hidden field like so

<input type="hidden" name="user[]" value="<?=$row['email']; ?>" />

 

I'm testing to make sure it has all of the emails, when I click on the 'Submit' button, it should display every email that the newsletter is going to get sent to for testing purposes.

 

What happens is, it displaying every email 13 different times.

There are 128 different emails in the system, so logically it should only show 128 emails, but instead it's showing me 1,664 emails.

Here is the code:

$subscriber=$_POST['user'];

	$together = implode(", ", $subscriber);
	for($i = 0; $i < count($subscriber); $i++){

		echo "$together<br>";
	}

 

Can anybody tell me why it's showing every email multiple times, and not just once?

 

Thanks in advance

I

Link to comment
https://forums.phpfreaks.com/topic/132447-solved-implode-function/
Share on other sites

You're imploding the data, which creates (in this case) a comma delimited string containing all of the values in the array. You then loop through the array echoing the string each time.

 

You should either be looping or imploding. Not both.

Archived

This topic is now archived and is closed to further replies.

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