TCPDF-从mysql打印表显示重复的第一行 [英] TCPDF - printing table from mysql showing repeated first row

查看:79
本文介绍了TCPDF-从mysql打印表显示重复的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是TCPDF的新手.我面临的一个小问题是所有输出数据都显示同一行.我的意思是第一条记录重复了数据库中总数据(行)存在的次数.这是我的代码

I am new to TCPDF. The small problem that I am facing is that all output data is displaying the same row. I mean the first record is repeated the number of times the total 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;
}
</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技能不是那么好,我可能错过了一个小小的愚蠢的细节.任何帮助将不胜感激,在此先感谢:)

It could be a small stupid detail that I am missing as my php/mysql skills aren't that great. Any help would be much appreciated, thanks in advance :)

推荐答案

$p_title来自哪里? $row_Pro_Record是包含行数据的变量.因此,您在表格内应该有类似

Where is $p_title coming from ? $row_Pro_Record is the variable that contains your row data. So inside you table you should have something like

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

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

where title is the name of the column, instead of

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

已阅读 mysql_fetch_assoc文档,其中显示了遍历结果的好例子:

have a read of the mysql_fetch_assoc docs it shows a nice example of looping over results :

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

这篇关于TCPDF-从mysql打印表显示重复的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆