在我的代码中,我想包括while循环从数据库获取信息&将其以表格形式发送给用户。我试着搜索了很多文章,但实际上没有解决方案。下面是我的代码:
$message->setBody('
<html>
<body>
<table style="margin-top:10px; width: 680px; border:0px;">
<tr>
<th width="80%">Product Details</th>
<th width="20%">Amount</th>
</tr>'); /* This is Line 43 */
while ($row = mysql_fetch_array($results2)){
$message->setBody .= ('<tr>
<th width="80%">'.$row["product_name"].' - '.
$row["quantity"].' '.$row["type"].'</th>
<th width="20%">₹ '.$row["subtotal"].'</th>
</tr>');
}
$message->setBody .= ('</table>
</body>
</html>',
'text/html');
随之而来的错误是:
Parse error: syntax error, unexpected ';' in /home/public_html/example.com/
test.php on line 43
我知道我一定是错过了一些基本的东西,但却无法发现。如有任何帮助,不胜感激。
编辑
结果来自while循环(在电子邮件外测试),所以这不是问题。
最后部分错误
$message->setBody .= ("</table>
</body>
</html>",
'text/html');
错误是" 'Unexpected ',' in file in line no. "62"。
首先,您的代码中有一些语法错误。一个地方你调用$message->setBody作为函数,一个地方你使用它作为对象属性。其次,如果有下面的工作版本给你。最后,在将来——更仔细地阅读你的代码,并尝试理解在开发过程中你在做什么。你的代码有些部分没有任何意义。
<?php
$html = "
<html>
<body>
<table style='margin-top:10px; width: 680px; border:0px;'>
<thead>
<tr>
<th width='80%'>Product Details</th>
<th width='20%'>Amount</th>
</tr>
</thead>
<tbody>";
while ($row = mysql_fetch_array($results2)) {
$html .= "
<tr>
<td width='80%'>{$row["product_name"]} - {$row["quantity"]} {$row["type"]}</td>
<td width='20%'>₹ {$row["subtotal"]}</td>
</tr>";
}
$html .= "
</tbody>
</table>
</body>
</html>";
$message->setBody($html, "text/html");
?>