0

I am facing a problem to fetch array in codeigniter

$data['one']=$this->db->query($sql1);
$data['tho']=$this->db->query($sql2);
$data['three']=$this->db->query($sql3);

I am trying to do this following code I am getting error

Fatal error: Call to a member function result() on a non-object in

If I do var_dump($data['one']); I am getting the following displayed:

Array
(
 [0] => stdClass Object
 (
  [date] => 2013-09-28
 )
 [1] => stdClass Object
 (
  [date] => 1970-01-01
 )
 [2] => stdClass Object
 (
  [date] => 2013-09-28
 ) 
)

1 Answer 1

2

You can do (in the controller) something like this foreach one of your arrays:

  foreach ($data['one']->result() as $row)
  {
        echo $row->date; //or whatever the query returns
  }

If you want to print it on the view you do it like this:

  foreach ($one->result() as $row)
  {
        echo $row->date; //or whatever the query returns
  }

See more in the official documentation about queries here

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.