0

I have a problem on CodeIgniter and MySQL logic maybe. I have two queries, I have executed them, each query has a different array variable and I want to put in one variable.

$query1 = $this->db->query("select a from base where id=1");
$query2 = $this->db->query("select b from base where id=2");
$this->data['result'] = $query1->result_array();
$this->data['result'] = $query2->result_array();

It's overwritten.

1
  • try this-: $this->data[] = $query1->result_array(); and in the next line $this->data[] = $query2->result_array(); Commented Sep 14, 2015 at 4:25

3 Answers 3

1

You are rewriting $this->data['result'] you need to add as sub array like

$this->data['result'][] = $query1->result_array();
$this->data['result'][] = $query2->result_array();

so now it will like

$this->data['result'][query1_result_array,query2_result_array]
Sign up to request clarification or add additional context in comments.

Comments

0

I think you can use it like

$query = $this->db->query("select a from base where id IN(1,2)");

Than use $this->data['result'];

Comments

0

You can try an array_merge too:

$final = array_merge($query1->result_array(),$query1->result_array());

This works only provided that result_array() returns an index-based array (that is, not an associative array)

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.