java - How to pass data using json array? -
the data print array object, object can't push data table
[{"brand_name":"edna","product_type":"smacker","product_flavour":"crispy","dealer_price":null,"price ":null,"open_stock":[{"openstock":"100.00"}],"total_purchase":[{"totalpurchase":null}],"free_issuese_in":[{"freeissuesein":null}],"stock_tra_in":[{"stocktrain":"100.00"}],"totalsales":[],"stocktraout":[{"stout":"0.00"}],"freeissuesout":[{"sum(stock_minus)":null}],"clossing_blnc":-100},{"brand_name":"edna","product_type":"large","product_flavour":"orange","dealer_price":null,"price ":null,"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":"0.00"},{"stock_plus":"0.00"}],"stocktraout":[{"stout":"0.00"}],"freeissuesout":[{"sum(stock_minus)":null}],"clossing_blnc":-277},{"brand_name":"edna","product_type":"large","product_flavour":"orange","dealer_price":null,"price ":null,"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":"0.00"},{"stock_plus":"0.00"}],"stocktraout":[{"stout":"0.00"}],"freeissuesout":[{"sum(stock_minus)":null}],"clossing_blnc":-277},{"brand_name":"edna","product_type":"large","product_flavour":"orange","dealer_price":null,"price ":null,"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":"0.00"},{"stock_plus":"0.00"}],"stocktraout":[{"stout":"0.00"}],"freeissuesout":[{"sum(stock_minus)":null}],"clossing_blnc":-277},
this picture show how data pass table. if print array show correct data.
but data showing this
my javascript pass data using 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>' );
model data
$sql="select tu.user_id, tt.territory_id, tp.product_id, tpt.product_type, tb.brand_name, product_flavour 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 tshm.status = 1 "; $query = $this->db->query($sql); foreach ($query->result() $row){ $sql2="select sum(`dealer_price`) dealer_price `tbl_product_has_price` `product_id` = $row->product_id ";//price(rd) $query2= $this->db->query($sql2); $dealer_price =$query2->result(); $sql3="select sum(price) price tbl_purchase_order_has_details product_id = $row->product_id "; //price(pur) $query3 = $this->db->query($sql3); $price =$query3->result(); $sql4="select sum(`stock_plus`) totalpurchase `tbl_stock_history_manage` `stock_type` = 'purchase' , product_id = $row->product_id , territory_id = $row->territory_id , user_id = $row->user_id"; //total purchase $query4 = $this->db->query($sql4); $toatal_purchase =$query4->result(); $sql5="select sum(`stock_plus`) freeissuesein `tbl_stock_history_manage` `stock_type` = 'purchase_free' , product_id = $row->product_id , territory_id = $row->territory_id , 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`) stocktrain `tbl_stock_history_manage` `stock_type` = 'stock adjesment pluse' , product_id = $row->product_id , territory_id = $row->territory_id , 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`) openstock `tbl_stock_history_manage` product_id = $row->product_id , territory_id = $row->territory_id , user_id = $row->user_id "; //open stock $query7= $this->db->query($sql7); $openstock =$query7->result(); $sql8="select `stock_plus` `tbl_stock_history_manage` `stock_type` = 'sales' , product_id = $row->product_id , territory_id = $row->territory_id , user_id = $row->user_id"; //totalsales $query8 = $this->db->query($sql8); $totalsales =$query8->result(); $sql9="select sum(`stock_minus`+`mobile_stock_minus`) stout `tbl_stock_history_manage` `stock_type` = 'stock adjesment pluse' , product_id = $row->product_id , territory_id = $row->territory_id , user_id = $row->user_id"; //stocktraout $query9= $this->db->query($sql9); $stocktraout =$query9->result(); $sql10="select sum(stock_minus) `tbl_stock_history_manage` `stock_type` = 'free' , product_id = $row->product_id , territory_id = $row->territory_id , 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;
actually don't know solution question . if java script can pass data loop inside forloop or .? please if 1 me print correct data in table...
i'm not sure you're asking if problem want values each items pay attention output json.parse json code not simple 1 dimensional array. example if want access in loop value called openstock, can that:
for( var x=0; x<order.length;x++){ ... +'<td>'+ order[x].open_stock[0].openstock +'</td>' }
Comments
Post a Comment