Question

table_1

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

table_2

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

based on these tables I want to make a table with joining them.

the first file, show.php

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

the second file to print the joining table, 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;

//...

but the result show all the rows :

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

how to make the result just show one row like this? :

+------+--------+------+
| code | name   | rate |
+------+--------+------+
| 1056 | Alex   |    9 |
+------+--------+------+
Was it helpful?

Solution

Now Check it

$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."'");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top