我有两张表machine_info
和parts_repalced
表machine_info
id | machine_name | desc | date_added | parts_ref
1 | printer | desc1| 09/09/15 | 7
表parts_replaced
id | machine_ref_id | partno | qty
1 | 7 | KFRy23 | 2
2 | 7 | RY7RA1 | 4
现在我希望它加入并显示如下
id | machine_name | desc | date_added | partno | qty
1 | printer | desc1| 09/09/15 | KFRy23 | 2
| RY7RA1 | 4
这是我到目前为止所做的......
$result = $db->query("SELECT * FROM machine_info LEFT OUTER JOIN parts_replaced ON machine_info.id = parts_replaced.machine_ref_id");
$data = "";
while($r = $result->fetch_object()) {
if ($data != "") {$data .= ",";}
$data .= '{"id":"' . $r->id . '",';
$data .= '"machine_name":"' . $r->machine_name. '",';
$data .= '"desc":"' . $r->desc. '",';
$data .= '"date_added":"' . $r->date_added. '",';
$data .= '"partno":"' . $r->partno. '",';
$data .= '"qty":"'. $r->qty. '"}';
}
$result->free();
$data ='{"records":['.$data.']}';
$db->close();
echo($data);
结果的问题是它给我一个重复的结果
任何帮助将不胜感激。提前谢谢..