TCPDF - print table from mysql showing duplicate first row

I am new to TCPDF. The little problem I am facing is that all the output is displaying the same string. I mean the first record is repeated the number of times the shared data (rows) exist in the database. Here is my code

$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;
<table id="gallerytab" width="600" cellspacing="2" cellpadding="1" border="0">
        <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>
$tbl_footer = '</table>';
$tbl = '';

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


This might be a silly little detail that I am missing as my php / mysql skills are not that great. Any help would be much appreciated, thanks in advance :)


source to share

1 answer

Where from $p_title

? $row_Pro_Record

is a variable containing your string data. Therefore, inside the table, you should have something like



where title

is the name of the column, not



read the mysql_fetch_assoc docs , it shows a good example of iterating over the results:

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




All Articles