Array with information from a database

2

I'm starting an email system for a client. It has SMTP from locaweb and they have an API for sending mail. So far so good I can send the emails using their api, but I came across a question that I can not solve.

It's like this: I need to mount an array with the email, but the emails are in the database, so how do I loop the replay inside the array?

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

I tried this way:

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

But without success how can I solve this. Can someone give me a light?

    
asked by anonymous 15.04.2015 / 00:58

1 answer

3

Can not create a repeat loop within an array. You can create the email array using the query's own return. At 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];
    
15.04.2015 / 03:14