Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3342672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:51:58+00:00 2026-05-18T00:51:58+00:00

I am trying to figure out how to put a mysql query result into

  • 0

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;
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:51:59+00:00Added an answer on May 18, 2026 at 12:51 am
    $emails_array = array();
    
    while($row = mysqli_fetch_array($get_emails)) {
        $emails_array[] = explode(", ", $row['Email']);
    }
    
    foreach($emails_array as $value) {
      mail_function($value);
    }
    

    Or

    while($row = mysqli_fetch_array($get_emails)) {
      foreach(explode(", ", $row['Email']) as $value) {
        mail_function($value);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I am trying to figure out a way to query my mysql
I've been trying for hours to figure out how to put a link into
HI all, I am trying to figure out how to put this into words
Trying to figure out the right way to query a MySql database and find
I am trying to figure out where should I put database operation for each
I'm trying to access the http://s3.amazonaws.com/commoncrawl/parse-output/segment/ bucket with boto. I can't figure out how
Trying to figure out how I can do this properly. The print_r looks like
I have a couple escaped characters in user-entered fields that I can't figure out.
i'm trying to figure this out for days and i can't find what the
Pulling my hair out, trying to figure out what's wrong here. Create table query:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.