数据打印像这个数组一个对象,对象 我无法将这些数据推送到我的表格中
[{" BRAND_NAME":" EDNA"" PRODUCT_TYPE":" Smacker"" product_flavour&#34 ;: " Crispy"," dealer_price":null," price":null," open_stock":[{" openstock&#34 ;:" 100.00"}]," total_purchase":[{" totalPurchase":空}]," free_issuese_in":[{& #34; freeIssueseIn":空}]," stock_tra_in":[{" stocktrain":" 100.00"}]," totalSales&# 34;:[]," stockTraOut":[{"粗壮":" 0.00"}]," freeIssuesOut":[{& #34; SUM(stock_minus)":空}]," clossing_blnc": - 100},{" BRAND_NAME":" EDNA"&# 34; PRODUCT_TYPE":"大"" product_flavour":"橙色"" dealer_price":空,"价格 ":空," open_stock":[{" openstock":" 277.00"}]," total_purchase":[{ " totalPurchase":" 150.00"}]," free_issuese_in":[{" freeIssueseIn":" 50.00" }]," stock_tra_in":[{" stocktrain":" 3.00"}]," totalSales":[{" stock_plus":" 0.00"},{" stock_plus":" 0.00"},{" stock_plus":&#34 ; 0.00"},{" stock_plus":" 0.00"}]," stockTraOut":[{"粗壮&#34 ;: " 0.00"}]," freeIssuesOut":[{" SUM(stock_minus)":空}]," clossing_blnc": - 277},{" BRAND_NAME":" EDNA"" PRODUCT_TYPE":"大"" product_flavour":& #34;橙色"" dealer_price":空,"价格 ":空," open_stock":[{" openstock":" 277.00"}]," total_purchase":[{ " totalPurchase":" 150.00"}]," free_issuese_in":[{" freeIssueseIn":" 50.00" }]," stock_tra_in":[{" stocktrain":" 3.00"}]," totalSales":[{" stock_plus":" 0.00"},{" stock_plus":" 0.00"},{" stock_plus":&#34 ; 0.00"},{" stock_plus":" 0.00"}]," stockTraOut":[{"粗壮&#34 ;: " 0.00"}]," freeIssuesOut":[{" SUM(stock_minus)":空}]," clossing_blnc": - 277},{" BRAND_NAME":" EDNA"" PRODUCT_TYPE":"大"" product_flavour":& #34;橙色"" dealer_price":空,"价格 ":空," open_stock":[{" openstock":" 277.00"}]," total_purchase":[{ " totalPurchase":" 150.00"}]," free_issuese_in":[{" freeIssueseIn":" 50.00" }]," stock_tra_in":[{" stocktrain":" 3.00"}]," totalSales":[{" stock_plus":" 0.00"},{" stock_plus":" 0.00"},{" stock_plus":&#34 ; 0.00"},{" stock_plus":" 0.00"}]," stockTraOut":[{"粗壮&#34 ;: " 0.00"}]," freeIssuesOut":[{" SUM(stock_minus)":空}]," clossing_blnc": - 277},
此图片显示数据如何传递到表中。如果我打印数组它显示正确的数据。
但数据显示如下
我的javascript我使用json传递数据
success: function (data){
alert(data);
var order = JSON.parse(data);
var order_detail = [];
$j('#lbl_rescount').text.length;
$j('#rows_token').val.length;
// var or_de =[];
if (order!== 0) {
for( var x=0; x<order.length;x++){
order_detail.push(
'<tr>'
+'<td>'+ order[x].brand_name + '</td>'
+'<td>'+ order[x].product_type + '</td>'
+'<td>'+ order[x].product_flavour +'</td>'
+'<td>' + order[x].dealer_price +'</td>'
+'<td>' + order[x].price +'</td>'
+'<td>' + order[x].open_stock +'</td>'
+'<td>' + order[x].total_purchase+'</td>'
+'<td>'+ order[x].free_issuese_in + '</td>'
+'<td>'+ order[x].free_issuese_in + '</td>'
+'<td>' + order[x].tot +'</td>'
+'<td>' + order[x].total_sales +'</td>'
+'<td>'+ order[x].stock_tra_out + '</td>'
+'<td>'+ order[x].free_issues_out + '</td>'
+'<td>'+ order[x].clossing_blnc + '</td>'
+'</tr>'
);
模型我得到数据
$sql="SELECT
tu.user_id,
tt.territory_id,
tp.product_id,
tpt.product_type,
tb.brand_name,
product_flavour
FROM
tbl_product tp
INNER JOIN
tbl_product_type tpt ON tpt.product_type_id = tp.product_type_id
INNER JOIN
tbl_category tc ON tc.id_category = tp.category_id
INNER JOIN
tbl_brand tb ON tb.id_brand = tc.brand_id
INNER JOIN
tbl_product_flavour tpf ON tpf.product_flavour_id = tp.flavour_Id
INNER JOIN
tbl_stock_history_manage tshm ON tshm.product_id = tp.product_id
INNER JOIN
tbl_territory tt ON tt.territory_id = tshm.territory_id
INNER JOIN
tbl_user tu ON tu.user_id = tshm.user_id
where
tshm.status = 1
";
$query = $this->db->query($sql);
foreach ($query->result() as $row){
$sql2="SELECT
SUM(`dealer_price`) AS dealer_price
FROM
`tbl_product_has_price`
WHERE `product_id` = $row->product_id
";//price(rd)
$query2= $this->db->query($sql2);
$dealer_price =$query2->result();
$sql3="SELECT sum(price) as price
from
tbl_purchase_order_has_details
WHERE
product_id = $row->product_id
"; //price(pur)
$query3 = $this->db->query($sql3);
$price =$query3->result();
$sql4="SELECT
SUM(`stock_plus`) as totalPurchase
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'PURCHASE'
AND
product_id = $row->product_id
AND territory_id = $row->territory_id
AND user_id = $row->user_id"; //total purchase
$query4 = $this->db->query($sql4);
$toatal_purchase =$query4->result();
$sql5="SELECT
SUM(`stock_plus`) AS freeIssueseIn
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'PURCHASE_FREE'
AND
product_id = $row->product_id
AND territory_id = $row->territory_id
AND user_id = $row->user_id"; //free issuse in
$query5= $this->db->query($sql5);
$free_issuese_in =$query5->result();
$sql6="SELECT
SUM(`stock_plus`+`mobile_stock_plus`) AS stocktrain
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'STOCK ADJESMENT PLUSE'
AND
product_id = $row->product_id
AND territory_id = $row->territory_id
AND user_id = $row->user_id"; //stock_tra_in
$query6= $this->db->query($sql6);
$stock_tra_in =$query6->result();
$sql7="SELECT
SUM(`stock_plus`-`stock_minus`)+sum(`mobile_stock_plus`-`mobile_stock_minus`) AS openstock
FROM
`tbl_stock_history_manage` WHERE
product_id = $row->product_id
AND territory_id = $row->territory_id
AND user_id = $row->user_id "; //open stock
$query7= $this->db->query($sql7);
$openStock =$query7->result();
$sql8="SELECT
`stock_plus`
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'SALES'
AND
product_id = $row->product_id
AND territory_id = $row->territory_id
AND user_id = $row->user_id"; //totalSales
$query8 = $this->db->query($sql8);
$totalSales =$query8->result();
$sql9="SELECT
SUM(`stock_minus`+`mobile_stock_minus`) AS stout
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'STOCK ADJESMENT PLUSE' AND
product_id = $row->product_id AND
territory_id = $row->territory_id
AND user_id = $row->user_id"; //stockTraOut
$query9= $this->db->query($sql9);
$stockTraOut =$query9->result();
$sql10="SELECT
SUM(stock_minus)
FROM
`tbl_stock_history_manage`
WHERE
`stock_type` = 'FREE'
AND
product_id = $row->product_id AND territory_id = $row->territory_id
AND user_id = $row->user_id"; //freeIssueseOut
$query10= $this->db->query($sql10);
$freeIssuesOut =$query10->result();
$return_array[] = array(
'brand_name'=>$row->brand_name,
'product_type'=>$row->product_type,
'product_flavour'=>$row->product_flavour,
'dealer_price'=>$dealer_price->dealer_price,
'price '=>$price->price ,
'open_stock'=>$openStock,
'total_purchase'=>$toatal_purchase,
'free_issuese_in'=>$free_issuese_in,
'stock_tra_in'=>$stock_tra_in,
//'tot'=> number_format(count($open_stock) > 0 ? $open_stock[0]->openstock:0,2)+($total_purchase[0])+($free_issuese_in[0])+($stock_tra_in[0]->stock),//total
'totalSales'=>$totalSales,
'stockTraOut'=>$stockTraOut,
'freeIssuesOut'=>$freeIssuesOut,
'clossing_blnc'=> number_format(count($stockTraOut)> 0 ? $stockTraOut[0]->stout :0,2)+( $freeIssuesOut[0]->stock_minus)+($totalSales[0]->totsales)-number_format(count($openStock) > 0 ? $openStock[0]->openstock :0,2)+($toatal_purchase[0]->stock_plus)//closing balance
);
}
return $return_array;
实际上我不知道我的问题的解决方案是什么。如果那个java脚本可以在forloop或。中传递for循环数据?如果有人帮我把正确的数据打印到表格中,请...
答案 0 :(得分:0)
我不确定你要问的是什么,但如果你的问题是你想要每个项目的值,那么请注意JSON.parse到你的JSON代码的输出不是简单的一维数组。因此,例如,如果您想要循环访问名为openstock的值,那么您可以这样做:
for( var x=0; x<order.length;x++){
...
+'<td>'+ order[x].open_stock[0].openstock +'</td>'
}