Emailing Multiple Query results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnc71
Forum Newbie
Posts: 10
Joined: Tue Jun 24, 2008 2:19 am

Emailing Multiple Query results

Post 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);  
}
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Re: Emailing Multiple Query results

Post 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);  
 
Post Reply