Page 1 of 1

Emailing Multiple Query results

Posted: Fri Nov 07, 2008 7:33 pm
by johnc71
I have a DB with pin numbers. Lets say I want to get first 5 pin numbers where the "active" field is set to "yes" and email them to customer. With the code below I will be sending 5 emails but I want to send 1 email with 5 pins. Can someone point me in right direction ? Thanks!

Code: Select all

$sql1 = mysql_query("SELECT * FROM pins WHERE active='Yes' limit 5") or die mysql_error()); 
 
while($r1 = mysql_fetch_assoc($sql1))
{
$pin_id = $r1['pin_id'];
$pin_number = $r1['pin_number'];
 
@mail($mail_to, $email_subject, $pin_number,$from);  
}

Re: Emailing Multiple Query results

Posted: Fri Nov 07, 2008 11:13 pm
by LiveFree
You could do something along the lines of:

Code: Select all

 
$data = ""; // Will hold all of the pin numbers
while($r1 = mysql_fetch_assoc($sql1))
{
$pin_id = $r1['pin_id'];
$pin_number = $r1['pin_number'];
$data .= $pin_number . "\n";
}
@mail($mail_to, $email_subject, $data,$from);