0

表格1

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

表_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 |
+------+--------+------+
4

1 回答 1

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."'");
于 2013-01-08T04:20:22.537 回答