Page 1 of 1

How to get results from a while loop in to the body of email

Posted: Tue Feb 24, 2009 9:58 am
by mds1256
see my code

Code: Select all

 
    <?php
    include 'config.php';
include 'opendb.php';
 
    $query = "SELECT id, username, subject, date, status, escalated FROM `helpdesk` WHERE `date` < CURDATE()-14 and status LIKE '%Open' and escalated is NULL";
    $result = mysql_query($query) or die('Error : ' . mysql_error());
    $numrows = 0;
    $numrows = mysql_num_rows($result);
    
    while (list($id, $username, $subject1, $date, $status, $escalated) = mysql_fetch_array($result, MYSQL_NUM)) {
    
$message = "$id";
    };
 
$to = "me@me.com"; 
$subject = "Call Updates"; 
$email = "test@test.com";
 
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
 
 
include 'closedb.php';
 
?>
 
 
basically its for esculation on a helpdesk facility i have made. it needs to list the call ref number for the ones that over 14days old and send an email. problem is its only sending 1 result. i know why as the $message variable is getting overwritten by the loop each time it is looping but how can i stop this and allow it to list all results?

Re: How to get results from a while loop in to the body of email

Posted: Tue Feb 24, 2009 3:47 pm
by Randwulf
Instead of overwriting the $message variable you could add to it like this:

Code: Select all

 
$message .= $id
 
(Notice the period before the equals)

That way if the first id is 'jean le baptise' and the second is 'snow ninja', $message would become 'jean le baptistesnow ninja'. You may want to put a space in there for that reason.

Re: How to get results from a while loop in to the body of email

Posted: Wed Feb 25, 2009 3:49 am
by mds1256
perfect!!!

thanks :D