我有Item_model返回的以下数据数组。此数组包含 MySQL 表列的一些值,例如"r_qty"和"ap_qty"。
$this->data['issueData']=$this->Item_model->ItemRequestfromHDData($id);
Item_model
function ItemRequestfromHDData($id)
{
$this->db->select('store_update_stock.*,store_update_stock_details.*,tbl_user.username,store_item.*,
sum(qty) as avqty, sum(store_update_stock_details.r_qty) as r_qty,
sum(store_update_stock_details.ap_qty) as ap_qty');
$this->db->from('store_update_stock_details');
$this->db->join('store_update_stock', 'store_update_stock.update_stock_id=store_update_stock_details.update_stock_id');
$this->db->join('tbl_user', 'store_update_stock.supplier=tbl_user.userId');
$this->db->join('store_item', 'store_update_stock_details.item=store_item.item_id', 'left');
$this->db->where(array('store_update_stock.update_stock_id' => $id, 'store_update_stock_details.status' => 1));
$this->db->group_by('store_item.item_id');
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
}
return false;
}
我想将这两列/值分配给变量。我尝试了以下作业。
$r_qty = $data['r_qty'];
$ap_qty = $data['ap_qty'];
但没有得到预期的结果。可能出了什么问题?谁能帮忙?
根据代码点火器文档,
结果((
此方法将查询结果作为对象数组或 失败时为空数组。
通常,您将在 foreach 循环中使用它,如下所示:
$query = $this->db->query("YOUR Q enter code here QUERY");
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}
所以,你的代码应该是
foreach ($this->data['issueData'] as $data)
{
$r_qty = $data->r_qty;
$ap_qty = $data->ap_qty;
}