0

I wonder if you could help me figure this out. I am retrieving values (specifically email) from database, and I want to store it in an array.

My problem is that I don't know how to store multiple values and retrieve them separately so that I can send those address with emails. I tried the code below but it didn't work.

$email = "select *  from student";
if ($p_address = mysql_query($email)) {
    while($row = mysql_fetch_assoc($p_address)) {
        $address = mysql_result($row, 0);
    }
}

The only thing that my code does is to send all of the emails to a single address, and that single address is the first entry in the database. Also note that the number of emails sent to tat particular address corresponds to the number of addresses in the database.

Thanks if you could help.

4

4 回答 4

4

做就是了

$email = "select *  from student";
if ($p_address = mysql_query($email)) {
    $address = array();  
    while($row = mysql_fetch_assoc($p_address)) {
        $address[] = mysql_result($row, 0);
    }
}
print_r($address);

要使用它,您可以调用数组值,例如:

$address[0],$address[1],$address[2],$address[...]

要在邮件功能中使用所有地址,请使用:

$all_address = implode(',', $address);
mail($all_address, $email_subject, $thankyou);
于 2013-05-05T16:08:31.393 回答
2

尝试

<?php
$email = "select *  from student"; 
if ($p_address=mysql_query($email))
{
  $address = array();
  while($row = mysql_fetch_assoc($p_address))
  { 
     $address[] = $row[fieldname];
  }
  $all_address = implode(',', $address);
}
?>
于 2013-05-05T16:07:24.520 回答
2

你可以这样做:

$addresses = array();
$query = mysql_query("select *  from student");
while($row = mysql_fetch_assoc($query))
{
    $addresses[] = row;
}

foreach ($addresses as $address)
{
    echo $address; // Or do what you want to do with each address
}
于 2013-05-05T16:07:56.570 回答
0

尝试这个

$email = "select *  from student";
if ($p_address = mysql_query($email))
{
    $address=array();   
    while($row = mysql_fetch_assoc($p_address))
    {
        $address[] = $row['your_column_name'];
    }
}
于 2013-05-05T16:10:59.657 回答