Array with database information

Asked

Viewed 3,945 times

2

I am starting an email sending system for a customer. It has SMTP from Locaweb and they have an API for sending email. So far so good I can send the emails using their api, but I came across a question that I am not able to solve.

Here’s the thing: I need to assemble an array with the emails, but the emails are in the database, so how can I loop the loop inside the array?

$to = array(
    '[email protected]', 
    '[email protected]',
    '[email protected]',
    '[email protected]',
)

I tried so:

$to = array(
    foreach ($query as $row):
        echo '"'. $row->email . '",' 
    endforeach;
)

But unsuccessfully how can I resolve this. Can anyone give me a light?

  • you want to send an email to several people in the field para/to email? which library is using to send email?

  • 1

    If you search the data with PDO and use Fetchassoc it automatically brings an Array

1 answer

3


It is not possible to create a repeat loop within an array. You can create the email array using the query return itself. With each return line you feed the email array.

$sql = "sua query aqui";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
    $arrayEmails[] = $row["campo_que_contem_o_email"];
}

echo $arrayEmails[0];
echo $arrayEmails[1];
echo $arrayEmails[n];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.