2011-06-01 114 views
1

這是我的dynamicList(你幫我創建了多個列) 但是我忘記了通過創建多個列/行inseide表,如果我有20個項目要顯示,我必須等到整個桌子準備好了,我不想那樣做。DynamicList with Multiple Columns

我該如何解決這個問題,以便在新表格中顯示每行?

if ($productCount > 0) { 
     $i=0; 
     $dynamicListBody = '<table width: 90%; margin-right: auto; margin-left: auto; color: #00E6AA;>'; 
     while($row = mysql_fetch_array($sql)){ 
      $id = $row["id"]; 
      $product_name = $row["product_name"]; 
      $details = $row["details"]; 
      $price = $row["price"]; 
      $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); 
     $dynamicListBody .= ($i==0) ? '<tr>':''; 
     $dynamicListBody .= '<td width="10%"> 
        <img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" height="80px" width="40px" alt="' . $product_name . '" /> 
        </td> 
        <td width="35%"> 
        <span class=itmttl>' . $product_name . '</span> 
        <br /> 
        <span class=text>' . $details . ' 
        <br /> 
        €' . $price . '</span> 
        <br /> 
         <form name="bd_itm" id="bd_itm" method="post" action="help_scripts/cart_functions.php"> 
        <input type="hidden" name="pid" id="pid" value="' . $id . '" /> 
        <input type="submit" name="button" id="button' . $id . '" value="Add to Cart" /> 
        <br /> 
        <br /> 
         </form> 
        </td>'; 
     $dynamicListBody .= ($i==1) ? '</tr>':''; 
     $i++; 
     ($i==2) ? $i=0:''; 
     } 
     $dynamicListBody .='</table>'; 
     } else { 
      $dynamicListBody = "We have no products listed in our store yet"; 
      } 
     mysql_close(); 

回答

1

不,你不必等到孔表已準備就緒,但實際上等到PHP加載完成它。也就是說,PHP在顯示洞穴腳本之前運行它。

我認爲顯示每行作爲單獨的表是非常糟糕的想法。相反,優化您的PHP,使其運行速度更快,或者在while循環結束之前添加flush()(在每行末尾)。