我可以结合 JSON 的这个结果吗?
问题是,在尝试在 codeigniter 上组合此结果时,我在调用成员 result_array() 时收到错误致命错误
$this->alerts
->select('products.id as productid, products.code as code, products.name, products.price, sum(purchase_items.quantity)')
->from('products');
$this->alerts->join('purchase_items', 'products.id = purchase_items.product_id');
$this->alerts->group_by("products.id");
echo "Total Purchases";
echo $this->alerts->generate();
$this->alerts
->select('products.id as productid, products.code as code, products.name, products.price, sum(sale_items.quantity)')
->from('products');
$this->alerts->join('sale_items', 'products.id = sale_items.product_id');
$this->alerts->group_by("products.id");
echo "Total Sales";
echo $this->alerts->generate();
结果为 JSON:
{"sEcho":0,"iTotalRecords":210,"iTotalDisplayRecords":210,"aaData":[["522","E12345","BAMBOO SCARF","100.00","3"]],"sColumns":"productid,code,products.name,products.price,sum(sale_items.quantity)"}
{"sEcho":0,"iTotalRecords":210,"iTotalDisplayRecords":210,"aaData":[["522","E12345","BAMBOO SCARF","100.00","15"]],"sColumns":"productid,code,products.name,products.price,sum(sale_items.quantity),productid,code,products.name,products.price,sum(purchase_items.quantity)"}
从 json 获取数据的脚本:
$(document).ready(function() {
$('#fileData').dataTable( {
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "desc" ]],
"bJQueryUI": true,
"sDom": '<"H"frlT><"clear">t<"clear"><"F"ip>',
//<"H"T><"clear">
//"sDom": '<"top"i>rt<"bottom"flp><"clear">',
'bProcessing' : true,
'bServerSide' : true,
'sAjaxSource' : 'index.php?getdata',
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
},
"oLanguage": {
"sSearch": "Filter: "
},
"aoColumns": [
null,
null,
null,
null,
null,
{ "bSortable": false }
]
} );
} );