douyi9705 2015-06-18 09:23
浏览 53

混合HTML代码与PHP代码

I am trying to use tcpdf library to generate pdf. I have a php file which contains variables like name,company name etc. But for displaying the products I am passing the array to php. Now I want to display each element of array in a table row for that I have to write the php code but somehow I am having problem mixing PHP code with html code.Here is the part whihch contains the problem

    $html .= '<br><br>
              <table border="1" cellpadding="5">
                <tr>
                    <td colspan="3">Invoice # {invoice_ref_id}</td>            
                </tr>
                <tr>
                    <td><b>Product</b></td>
                    <td><b>Quantity</b></td>
                    <td align="right"><b>Amount (Rs.)</b></td>
                </tr>'.
                foreach($item as products): .'   //This part contains error
                <tr>
                    <td>'echo products['item']'</td>
                    <td>'echo products['quantity']'</td>
                    <td align="right">75</td>
                </tr>
                <tr>
                    <td colspan="3" align="right"><b>Total: 375</b></td>
                </tr>'
                endforeach;
             '</table>';

    $html .= '<br><br>Some more text can come here...';
  • 写回答

4条回答 默认 最新

  • dongle19863 2015-06-18 09:24
    关注

    You can't continue the html with a concatenation straight after the foreach. You have to do $html .= again.

    This

    </tr>'.
    foreach($item as products): .'   //This part contains error
    <tr>
    

    should be this

    </tr>';
    foreach($item as products): $html .= '   //This part contains error
    <tr>
    

    The same goes at the end of the foreach:

    </tr>';
    endforeach;
    $html .= '</table>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用