0

我正在使用以下查询:-

$qry=mysql_query("SELECT item,quantity,price,(quantity * price) as total FROM saleitems_T WHERE invoice = '$inv' ");

我正在尝试在邮件正文中使用 while 循环,但它不起作用。以下是代码。

$to="someone@somewhere.com";
$headers="Content-type: text/html\r\n";
$body = '
<html> <body>
Invoice details are as follows.<br />
'.while($row = mysql_fetch_array($qry)){
echo "<table><tr><td>";
echo $row['item'];
echo "</td><td>";
echo $row['quantity'];
echo "</td><td>";
echo $row['price'];
echo "</td><td>";
echo $row['total'];
echo "</td></tr>";} .'
</table></body></html>';

mail($to,$body,$headers);

检索到的行数因每张发票而异。现在我想将结果作为电子邮件发送。任何有关示例代码的帮助将不胜感激。

4

1 回答 1

0
$to = "someone@somewhere.com";
$headers = "Content-type: text/html\r\n";
$body = '<html><body>Invoice details are as follows.<br />';
foreach( mysql_fetch_array($qry) as $v ) {
$body .= "<table><tr><td>{$v['item']}</td>"    
         . "<td>{$v['quantity']}</td>"     
         . "<td>{$v['price']}</td>"  
         . "<td>{$v['total']}</td></tr></table></body></html>";       
}

mail($to,$body,$headers);
于 2012-09-13T15:18:57.330 回答