0

I have following data array returned by Item_model. This array included some values of MySQL tables columns such as 'r_qty' and '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;
    }

I want to assign these two columns / values to variables. I tried following assignments.

$r_qty = $data['r_qty'];
$ap_qty = $data['ap_qty'];

but didn't get the expected result. What may be going wrong ? Can anyone help ?

5
  • Please add model code also Commented Dec 17, 2019 at 17:26
  • I don't know what $this->data is. I also don't know what $data is. But I know they are not the same. Commented Dec 17, 2019 at 17:30
  • @ Anand Pandey. Pls. see my edit Commented Dec 17, 2019 at 17:33
  • @ Paul. Pls. see my edit Commented Dec 17, 2019 at 17:34
  • 2
    $q->result() returns an array of objects. So, $this->data['issueData'] is an array. The 1st element in that array will be an object. $val = $this->data['issueData'][0]; $r_qty = $val->r_qty; Commented Dec 17, 2019 at 17:45

1 Answer 1

1

As per codeigniter documentation,

result()

This method returns the query result as an array of objects, or an empty array on failure.

Typically you’ll use this in a foreach loop, like this:

$query = $this->db->query("YOUR Q enter code here QUERY");

foreach ($query->result() as $row)
{
    echo $row->title;
    echo $row->name;
    echo $row->body;
}

So, your code should be

foreach ($this->data['issueData'] as $data)
{
    $r_qty = $data->r_qty;
    $ap_qty = $data->ap_qty;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.