I am trying to figure out how to put a mysql query result into an array that can be accessed outside the while loop. Is this possible?
My test code that I am playing with is below. I want to send email to the email addresses in the array without creating the email code inside the while loop. That way I can inject the array result into the BCC field and it all goes out at once using the mail() function rather than opening a new smtp connection for each email - or so I think.
<?php
if(isset($_POST['btnSendToSelected']) && isset($_POST['checked']))
{
$checked = array_map('intval',$_POST['checked']);
$email_list = implode(", ", $checked);
$get_emails = mysqli_query($conn, "SELECT UserName, Email FROM users WHERE UserId IN ($email_list)")
or die($dataaccess_error);
while($row = mysqli_fetch_array($get_emails))
{
$emails = array($row['Email']);
$emails_array = implode(", ", $emails);
}
// send the email here outside the while loop...
}
elseif(isset($_POST['btnSendToSelected']) && !isset($_POST['checked']))
{
$msg = $msg_error;
}
?>