我已经使用左连接来返回我的 'allinvty3' 表中的所有数据,这是我的主文件,但它不起作用。它只会在我使用INNER时工作加入,但我想返回所有行,即使与我的所有表格都不匹配( 条形码,adjust_tb,branchtobranch_tb等 。)
<?php
require_once 'global.php';
if($_POST['type'] == 'item_tb'){
$row_num = $_POST['row_num'];
$result = mysqli_query($conn, "select ite_desc,ecr_desc, pric_cash, uom_lo, t.itemcode as itemcode ,sum(t.qty) as tqty
from (
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo, qty from allinvty3 as bc left JOIN barcode as ait on bc.in_code = ait.itemcode where ait.status='COMPLETE'
union all
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo,qty from allinvty3 as bb left JOIN branchtobranch_tb as ait on bb.in_code = ait.itemcode
union all
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo,qty from allinvty3 as sb left JOIN stockreturn_tb as ait on sb.in_code = ait.itemcode
union all
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo,qty from allinvty3 as adt left JOIN adjustment_tb as ait1 on adt.in_code = ait1.itemcode where ait1.status='APPROVED'
union all
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo, qty from allinvty3 as nt left JOIN notinclude_tb as ait on nt.in_code = ait.itemcode
union all
select ite_desc,ecr_desc, pric_cash, itemcode, uom_lo, (qty * -1) from allinvty3 as slp left JOIN soldout_pd as ait2 on slp.in_code = ait2.itemcode) as t
where ecr_desc LIKE '".strtoupper($_POST['name_startsWith'])."%' group by itemcode ") ;
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$item = $row['ecr_desc']. '|' . $row['ite_desc'].'|' .$row['itemcode']. '|' .$row['tqty'].'|'. $row_num;
array_push($data, $item);
}
echo json_encode($data);
}
?>