Hi there,
I have a table of invoices and have written the query to select the fields SUM the amount field and group by customer_ number to give totals for each customer.
It works fine when I print it to the screen, I get the individual customer details the number of invoices that make up the total and the total of their transactions. However when I try to email the results to the customer it adds the details of all the previous customers.
$sqlquery="SELECT email, customer_no, customer_inv, SUM(amount), COUNT(*) FROM $table GROUP BY customer_no";
$result = mysql_query($sqlquery)or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo "printing array results<br>";
print_r($row); Echo "<BR>";
$customer = $row['customer_no'];
$invoice=$row['customer_inv'];
$amount=$row['SUM(amount)'];
$transactions=$row['COUNT(*)'];
$email=$row['email'];
ECHO "Customer No: $customer<BR>";
ECHO "Email: $email<BR>";
ECHO "transactions: $transactions<BR>";
ECHO "Total Collected: $amount<p>";
$message.= "$customer \$$amount $transactions<BR>\n\r";
// this ends the message part
$from_name = "Someone";
$from_email = "someone@somewhere.com";
$to_name = "someone else";
$to_email = "$email";
$subject = "Paid today";
// headers need to be in the correct order...
//$headers .= "To:\r\n";
$headers = "From: $from_name<$from_email>\r\n";
$headers .= "Reply-To: $from_email\r\n";
$headers .= "X-Priority: 2\r\n"; //1 UrgentMessage, 3 Normal
$headers .= "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$headers .= "X-Sender: $from_name<$from_email>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 1\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: $from_email\n";
// send the message :-)
mail("$to_name<$to_email>", $subject, $message, $headers);
}
So what do I need to do to get it to email only the details for the customer it is emailing?