2016-09-26 46 views
0

我有一个简单的问题,基本上我已经写了一些代码,我已经写了一些php代码来显示一些html之前的代码,然后是一个页脚......问题在于HTML是显示在这里先页脚,然后表.. 我想表中显示,然后再HTML页脚.. 是我的代码我如何在html之前显示php代码

if($orderCount == 0){ 
echo "<p><strong> No orders pending. Please try again later.</strong></p>"; 
    } 
echo "<table border=\"1\">\n"echo "<tr> <th bgcolor=\"blue\"> Order Summary</th></tr> 
<tr> <th bgcolor=\"blue\"> Title</th> 
    <th bgcolor=\"blue\"> Author</th> 
    <th bgcolor=\"blue\"> Format</th> 
    <th bgcolor=\"blue\"> Price</th> 
    </tr>"; 


    for($i=0;$i<$orderCount;$i++){ 

echo "<tr> 
    <td> $titleArray[$i]</td> 

      <td>$authorArray[$i]</td> 
       <td>$formatArray[$i]</td> 
        <td> $$priceArray[$i]</td> 
         </tr>"; 


} 
$total = number_format(array_sum($priceArray),2); 
echo " <tr> <td bgcolor=\"blue\"> Total price</td><td>&nbsp</td> <td>&nbsp</td><td align=\"right\">$$total</td></tr>" 


    ?> 
     <form action="myform.php" method="post"> 
     <ul> 
     <li>Payment Information</li> 

     </ul> 
     <label for="customer name">Customer Name</label> 
     <input type="text" name="customername" id="customername"> <br /> 
     <label for="address">Street Address</label> 
     <input type="text" name="city" id="city"> <br /> 
     <label for="state">State</label>   
     <input type="text" name="state" id="state"> <br /> 
     <label for="zip">Zip Code</label> 
     <input type="text" name="zip" id="zip"> <br /> 
     <input type="submit" value="Confirm Order"> 

    </form> 

</body> 
+1

'当你用它做,它可能会更好地工作。 –

+1

...并且在您打印完第一个标题后,您正在关闭表格行''...您确实需要检查您的打开和关闭标记... –

+0

...您还有一堆双美元符号,如'$$ total'。那是故意的吗?你应该尝试更好地构建你的代码,并通过它来尝试捕获所有的错误。 –

回答

1

您应该使用ob_get_contents()功能。

+0

为什么他应该使用它,如果他实际上是按照正确的顺序打印出来的?他的代码是一个不匹配HTML标签的游乐场,没有什么ob_get_contents()可以修复。 –

1

你可以只让PHP的,如果你关闭表标签`做HTML这样

<?php 
     // some php code you had 

?> 
    your html 
    <?php 
    // resume php code 
?>