Jump to content

Why is my simple implode array failing?


DBookatay

Recommended Posts

I am trying to create a mailing list, with the email addresses being pulled from the dB. I have this:

$emails = array($row['email']);
$list .= implode('; ', $emails);

 

Which returns all of the values from the dB, but it is not creating the "; " (semicolon and space) between each email address.

Link to comment
Share on other sites

Try:

 

$list .= implode('; ', $row['email']);

 

I am trying to create a mailing list, with the email addresses being pulled from the dB. I have this:

$emails = array($row['email']);
$list .= implode('; ', $emails);

 

Which returns all of the values from the dB, but it is not creating the "; " (semicolon and space) between each email address.

Link to comment
Share on other sites

Just from the context of those two lines, a few things can be said:

 

1. $row is already an array (What does the index "email" actually hold?)

 

2. $emails contains a two dimensional array

 

3. A variable that does not yet exist in the script context is being concatenated onto.

 

We need to see ALL of the relevant code logic in order to be able to properly help you.

Link to comment
Share on other sites

All of the code:

$query = "SELECT * FROM mailinglist ORDER BY email";
$result = mysql_query($query); 
$numrows = mysql_num_rows($result); 
for($x = 0; $row = mysql_fetch_array($result); $x++) {
 $id = $row['id'];
 $email = $row['email'];
 $links .= '<li><a href="mailto:'.$email.'">'.$email.'</a> <span class="delete"><a href="?cat=05&delete='.$id.'" onclick="return confirm(\'Are you sure you want to delete?\n This action CAN NOT be undone\')"><a></span></li>';
 $emails = array($row['email']);
 $list .= implode('; ', $emails);
}

Link to comment
Share on other sites

Something like this should work for you:

 

$emails = array(); //initialize
$query = "SELECT * FROM mailinglist ORDER BY email";
$result = mysql_query($query); 
$numrows = mysql_num_rows($result); 
while($row = mysql_fetch_array($result))
{
 $id = $row['id'];
 $email = $row['email'];
 $links .= '<li><a href="mailto:'.$email.'">'.$email.'</a> <span class="delete"><a href="?cat=05&delete='.$id.'" onclick="return confirm(\'Are you sure you want to delete?\n This action CAN NOT be undone\')"><a></span></li>';
 $emails[] = $row['email'];
}

$list = implode("; ", $emails);

 

Also, be sure to implement error checking logic into your code

Link to comment
Share on other sites

Something like this should work for you:

 

$emails = array(); //initialize
$query = "SELECT * FROM mailinglist ORDER BY email";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$email = $row['email'];
$links .= '<li><a href="mailto:'.$email.'">'.$email.'</a> <span class="delete"><a href="?cat=05&delete='.$id.'" onclick="return confirm(\'Are you sure you want to delete?\n This action CAN NOT be undone\')"><a></span></li>';
$emails[] = $row['email'];
}

$list = implode("; ", $emails);

 

Also, be sure to implement error checking logic into your code

 

 

This did it! Thank you!

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.