douchen7366 2014-02-14 16:35
浏览 7
已采纳

再次显示表而不重新处理所有PHP

I am making a form where a user can build a shopping cart and then once they submit it, they are taken to a page that displays their final contents in their cart. Behind the scenes, PHP is sending an email to myself which needs to contain the exact same table that was already rendered on the page once however I do not want to have to rebuild the table again, I would like to use the one that was already built. I don't know how to do this. My code works and everything is how I want it so don't

Below is a sample of code kind of like I have built, I cut out the repeat stuff to make it easier to look at.

    <table align="center" width="100%">
    <thead align="center">
    <tr>
    <td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Product</b></td>
    <td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Item ID</b></td>
    <td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Quantity</b></td>
    <td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Cost</b></td>
    </tr>
    </thead>
    <tbody>
    <?php
    $i = 0;
    $cmf073 = mysqli_result($result, $i, "cmf073");
    $cmf073total = mysqli_result($result, $i, "cmf073total"); 
    if($cmf073 > 0)
    {?>
    <tr>
    <td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
    Printable 3-Up Certified Mail® Form
    </td>
    <td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
    CMF-073
    </td>
    <td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
    <?php echo number_format($cmf073 * 1000, 0) ." Forms";?>
    </td>
    <td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
    $<?php echo number_format($cmf073total, 2);?>
    </td></tr>
    <?php
    }
    echo "<tr border='0'><td></td><td></td><td></td><td align='center'><b>Cost Estimate: ";
    echo "$".number_format($total, 2)."</b><br />
    <font style='font-size: 8px;'>Plus Tax, Shipping and Handling</font></td></tr></tbody></table>";

    }
    $email = "x@y.net";
    $subject = "New Customer Order Request from $company" ;
    $message =  "A new order request has been submitted on y.net</br></br>

    Contact Info:</br>
    $firstName $lastName</br>
    $phone | $email</br>
    $company</br>
    $address1</br>
    $address2</br>
    $city, $state $zip";
    $headers = 'From: x@y.net' . "
" .
    'Reply-To: x@y.net' . "
" .
    'Content-type: text/html; charset=utf-8' . "
" .
    'X-Mailer: PHP/' . phpversion();
    mail($email, $subject, $message, $headers);

So I need the table that was already generated at the top of the code to be placed in the bottom of the email $message. But I don't want to regenerate everything again since PHP has already created the table that I need. Sorry if this is confusing, I don't really know how to explain it. Thanks.

  • 写回答

4条回答 默认 最新

  • dougengqiu8031 2014-02-14 16:40
    关注

    At the beginning of the table

    <?php
    ob_start();
    ?>
    <table align='.....'
    //stuff
    //more stuff
    

    At the end of the table

    </table>
    <?php
    $myTable=ob_get_contents();
    ob_end_clean();
    echo $myTable;
    ?>
    

    Now in $myTable you have the content of the table, you can use it in your mail.

    $message.=$myTable;
    mail($email, $subject, $message, $headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)