0

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 |
+------+--------+------+

1 Answer 1

1

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."'");
4
  • now there's no row in result, only the field name. I also try with >> where '$code' = table_2.code and table_1.code = '$code' but no rows too.
    – andrian
    Jan 8, 2013 at 4:41
  • same result, no rows, only field name even though I add query at the last line with AND table_2.code = '".$code."'
    – andrian
    Jan 8, 2013 at 4:59
  • I already test your query in MySQL and it works in one row, but not from PDF result.
    – andrian
    Jan 8, 2013 at 5:14
  • Ok it works too in PDF result, I just found some little bit failure on my editing code. Thanks :)
    – andrian
    Jan 8, 2013 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.