2012-09-10 68 views
0

結果發送電子郵件: -如何從我使用下面的查詢陣列產生從MySQL查詢

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

我試圖使用郵件體內的while循環,但它不工作。以下是代碼。

$to="[email protected]"; 
$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); 

檢索到的行數在每張發票上都不相同。現在我想發送結果作爲電子郵件。任何示例代碼的幫助將不勝感激。

+0

首先你要研究如何在PHP – EbinPaulose

+0

發送電子郵件我已經補充說我使用的代碼,但是這是行不通的。 – mmdel

+1

語法完全錯誤。你不能做'$ string ='ss'。 while(..){..}' –

回答

0
$to = "[email protected]"; 
$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); 
+0

如果我想循環表格怎麼辦?你能編輯它嗎? – klaudia