DBookatay Posted February 16, 2013 Share Posted February 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted February 16, 2013 Share Posted February 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 16, 2013 Share Posted February 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
DBookatay Posted February 16, 2013 Author Share Posted February 16, 2013 Try: $list .= implode('; ', $row['email']); I tried and get an error: Warning: implode() [function.implode]: Invalid arguments passed in /home/dbookatay/superscienceenrichment.com/Admin/mailinglist.php on line 25 Quote Link to comment Share on other sites More sharing options...
DBookatay Posted February 16, 2013 Author Share Posted February 16, 2013 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); } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2013 Share Posted February 16, 2013 You need to do the implode after you're done making the array you want to implode. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 16, 2013 Share Posted February 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
DBookatay Posted February 18, 2013 Author Share Posted February 18, 2013 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.