php - PHPMailer populating emails from result of query -


i'm trying populate email addresses in phpmailer array returned query.

$query = 'select u.id, u.first_name, u.last_name, u.email users u inner join locations l on (u.location_id = l.id) district_id = 8 group id order first_name, last_name asc';  $result = mysqli_query($connection, $query); if (!result) {     die("database query failed: " . mysqli_error($result)); }  $recipients = array(); while ($row = mysqli_fetch_assoc($result)) {     $results[] = $row; } 

this gives me result such as:

array (     [0] => array ( [id] => 1 [first_name] => jon [last_name] => smith [email] => jon@domain.com )     [1] => array ( [id] => 3 [first_name] => dave [last_name] => virk [email] => dave@domain.com )     [2] => array ( [id] => 2 [first_name] => chris [last_name] => west [email] => chris@domain.com ) ) 

but being new working arrays i'm not sure how extract name , email of each user phpmailer.

i read example did this:

foreach($recipients $email => $name) {    $mail->addaddress($email, $name); } 

how adapt this?

in case be:

foreach($results $row) {     $mail->addaddress($row['email'], $row['first_name'].' '.$row['last_name']); } 

you need refer key values inside square brackets []


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -