dos3018 2014-08-26 05:44
浏览 16
已采纳

在php变量里面设置Email body而while循环不工作

So i am trying to send confirmation of an order via email. To do this i need to attach the body as a variable which is $body

So i have all my html code inside the $body. That part works great and it emails successfully.

However i need to loop out what ever was ordered so the customer knows what they ordered and what they paid for each item.

So here is the SQL query

// GET THE PRODUCTS THAT HAVE BEEN ORDERED
$w="SELECT
nfw_order_new_items.name,
nfw_order_new_items.qty,
nfw_order_new_items.price
FROM
nfw_order_new_items
WHERE
nfw_order_new_items.id_order = '$order_ID'";
$ww= mysql_query("$w") or die("Inv Rows ".mysql_error());

Then the body as an example, has my html in it. The $name, $qty and $price are where i want my loop to create the rows of the table depending on how many in the result. I have tried putting the loop outside body like below, but that doesnt work either. See below:

while(list($name,$qty,$price)= mysql_fetch_row($ww)){
$body = "<table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
          <tr style=\"font-size:12px; font-weight:bold; color:#FFF\">
            <td width=\"111\" bgcolor=\"#333333\" style=\"padding-left:5px;\">Product Name:</td>
            <td width=\"290\" bgcolor=\"#333333\">QTY:</td>
            <td width=\"67\" align=\"center\" bgcolor=\"#333333\">Price Each</td>
            <td width=\"121\" align=\"right\" bgcolor=\"#333333\" style=\"padding-right:5px; font-size:12px;  text-align:right;\">Total Price</td>
          </tr>
          <tr>
            <td style=\"padding-left:5px; font-size:12px;\">$name</td>
            <td style=\"padding-left:0px; font-size:12px;\">$qty</td>
            <td style=\"padding-left:0px; font-size:12px; text-align:center;\">$price</td>
          </tr>
        </table>"; }
  • 写回答

2条回答 默认 最新

  • dongzhuo1958 2014-08-26 05:51
    关注

    You dont need to print the table header each time you can do it like below

    $body = "<table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
              <tr style=\"font-size:12px; font-weight:bold; color:#FFF\">
                <td width=\"111\" bgcolor=\"#333333\" style=\"padding-left:5px;\">Product Name:</td>
                <td width=\"290\" bgcolor=\"#333333\">QTY:</td>
                <td width=\"67\" align=\"center\" bgcolor=\"#333333\">Price Each</td>
                <td width=\"121\" align=\"right\" bgcolor=\"#333333\" style=\"padding-right:5px; font-size:12px;  text-align:right;\">Total Price</td>
              </tr>";
    
    while(list($name,$qty,$price)= mysql_fetch_row($ww))
    {
        $body .= "<tr>
                <td style=\"padding-left:5px; font-size:12px;\">$name</td>
                <td style=\"padding-left:0px; font-size:12px;\">$qty</td>
                <td style=\"padding-left:0px; font-size:12px; text-align:center;\">$price</td>
              </tr>";
    }
    
    $body .= "</table>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目