使用连接表中的mPDF打印

时间:2013-01-08 02:55:57

标签: php mysql printing row mpdf

TABLE_1

+------+--------+
| code | name   |
+------+--------+
| 1056 | Alex   |
| 1057 | Rudy   |
| 1058 | Brian  |
+------+--------+

TABLE_2

+------+------+
| code | rate |
+------+------+
| 1056 |    9 |
| 1057 |    7 |
| 1058 |    8 |
+------+------+

基于这些表格,我想制作一个加入它们的表格。

第一个文件show.php

echo "<td><a href=print.php?code=$row[code]>Print....</a></td>";

打印连接表的第二个文件print.php

//...

$code = $_GET['code'];
$res = mysql_query("select table_1.code, table_1.name, table_2.rate from table_1, table_2, where table_1.code = table_2.code");

//...

while($row = mysql_fetch_array($res)){
    $a=$row['code'];
    $b=$row['name'];
    $c=$row['rate'];

$html .= '<tr><td>'.$a.'</td><td>' .$b. '</td><td>'.$c.'</td></tr>'; 
}
$html .= '</table> </center>';

$mpdf->WriteHTML($html,2); 
$mpdf->Output('print.pdf','I');
exit;

//...

但结果显示所有行:

+------+--------+------+
| code | name   | rate |
+------+--------+------+
| 1056 | Alex   |    9 |
| 1057 | Rudy   |    7 |
| 1058 | Brian  |    8 |
+------+--------+------+

如何让结果只显示一行? :

+------+--------+------+
| code | name   | rate |
+------+--------+------+
| 1056 | Alex   |    9 |
+------+--------+------+

1 个答案:

答案 0 :(得分:1)

现在检查

$res = mysql_query("SELECT table_1.code, table_1.name, table_2.rate FROM table_1 INNER JOIN table_2 ON table_1.code = table_2.code WHERE table_1.code ='".$code."'");