2012-03-15 47 views
3

我是TCPDF的新手。我面臨的小問題是所有輸出數據都顯示相同的行。我的意思是第一條記錄重複數據庫中所有數據(行)的存在次數。這裏是我的代碼TCPDF - 從mysql顯示重複第一行的表格

$tbl_header = '<style> 
table { 
    border-collapse: collapse; 
    border-spacing: 0; 
    margin: 0 20px; 
} 
tr { 
    padding: 3px 0; 
} 

th { 
    background-color: #CCCCCC; 
    border: 1px solid #DDDDDD; 
    color: #333333; 
    font-family: trebuchet MS; 
    font-size: 30px; 
    padding-bottom: 4px; 
    padding-left: 6px; 
    padding-top: 5px; 
    text-align: left; 
} 
td { 
    border: 1px solid #CCCCCC; 
    font-size: 25px; 
    padding: 3px 7px 2px; 
} 
</style> 
<table id="gallerytab" width="600" cellspacing="2" cellpadding="1" border="0"> 
<tr> 
     <th><font face="Arial, Helvetica, sans-serif">Products Title</font></th> 
     <th><font face="Arial, Helvetica, sans-serif">Product Specs</font></th> 
     <th><font face="Arial, Helvetica, sans-serif">Product Price</font></th> 
     <th><font face="Arial, Helvetica, sans-serif">Products Image</font></th> 
     </tr>'; 
$tbl_footer = '</table>'; 
$tbl = ''; 

while ($row_Pro_Record = mysql_fetch_assoc($Pro_Record)) { 
$tbl .= ' 
    <tr> 
     <td>'.$p_title.'</td> 
     <td>'.$p_size.'</td> 
     <td>'.$p_price.'</td> 
     <td><img width="120"src="http://localhost/product/images/'.$c_name.'/'.$p_image.'.jpg"></td> 
    </tr> 
'; 
} 
// output the HTML content 
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, ''); 

這可能是一個愚蠢的小細節,我很想念我的PHP/MySQL的技能不是很大。任何幫助將不勝感激,在此先感謝:)

回答

3

$p_title哪裏來的? $row_Pro_Record是包含行數據的變量。所以,你的表裏面,你應該有類似

<td>'.$row_Pro_Record['title'].'</td> 

其中title是列的名稱,而不是

<td>'.$p_title.'</td> 

mysql_fetch_assoc docs它顯示遍歷結果的一個很好的例子的讀:

while ($row = mysql_fetch_assoc($result)) { 
    echo $row["userid"]; 
    echo $row["fullname"]; 
    echo $row["userstatus"]; 
} 
+0

嗨@ManseUK $ p_title = $ row_Pro_Record ['product_title'];這是我早些時候宣佈的。事情是,記錄正常顯示在一個正常的PHP頁面,但只顯示生成PDF時的第一次重複記錄:/我卡住 – 2012-03-15 09:29:54

+0

@JunaidHassan包括你的完整代碼 - 你以上沒有工作 - 循環實際上並沒有循環什麼 - 因爲循環內部的變量保持靜態... – ManseUK 2012-03-15 09:31:42

+0

感謝您的意見到目前爲止。這裏是我的完整代碼 http://pastebin.com/BJ3UPFE5 – 2012-03-15 09:37:58