0

Two tables: first - kons, second - orders. Linked by field kons.id and order.id_kons
This is my query:

$this->db->select("k.id as k_id, DATE_FORMAT(k.datecreate, '%d/%m/%Y %H:%i:%s') as k_dt, o.id as o_id",false);
 $this->db->join('orders as o', 'o.id_kons = k.id','inner');
 $this->db->from('kons as k');<br>
 return $this->db->get()->result_array();

Result is (example, cut):

array(20) {
  [0]=>
  array(3) {
    ["k_id"]=>
    string(2) "45"
    ["k_dt"]=>
    string(19) "22/02/2014 15:41:35"
    ["o_id"]=>
    string(3) "533"
  }

  } .....

But i need something like that:

array(x) {
  [0]=>
  array(3) {
    ["k_id"]=>
    string(2) "45"
    ["k_dt"]=>
    string(19) "22/02/2014 15:41:35"
    ["o_id"]=>
    array(3) "533,534,536" or string(x) "533,534,536"
  }

1 Answer 1

3

You can use GROUP_CONCAT(expr) to get comma separated order ids how ever it is not recommended because of character length restriction of default set to 1024 character but it can be increased

$this->db->select("k.id as k_id, 
DATE_FORMAT(k.datecreate, '%d/%m/%Y %H:%i:%s') as k_dt, 
GROUP_CONCAT(o.id) as o_id",false);
$this->db->join('orders as o', 'o.id_kons = k.id','inner');
$this->db->from('kons as k');
$this->db->group_by("k.id");
return $this->db->get()->result_array();
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.