not able to create multi dimensional array in codeigniter not able to create multi dimensional array in codeigniter codeigniter codeigniter

not able to create multi dimensional array in codeigniter


There isn't a single query that comes mind that will do what you want. You are going to have to do some processing after you retrieve values from the db.

My suggestion is to use the mysql function Group_Concat() to return a comma separated list (a string) of skills. You can explode() that to create an array of skills.

In this example I have dropped the use of table alias names because I get confused otherwise :)

Because your where clause will only return one row (There is only one row with any given userid value in instanthire - right?) I am using $query->row_array() to get the data. This simplifies the return to a single array as opposed to the array of arrays that $query->result_array() returns.

public function get_request($requestid){    $this->db->select('instanthire.id, Group_Concat(instanthire_skills.skills) as skills');    $this->db->from('instanthire');    $this->db->join('instanthire_skills', 'instanthire.id = instanthire_skills.requested_id' , 'inner');    $this->db->where('instanthire.userid', $requestid);    $query = $this->db->get();    $result = $query->row_array();    $result['skills'] = explode(",", $result['skills']);    return $result;}

Let's assume you ran these two lines of code

$data = $this->get_request(2);var_dump($data);

and inside get_request() after$result = $query->row_array(); you added var_dump($result); you would get this

array (size=2)   'id' => string '2' (length=1)   'skills' => string 'core java,advance,.net' (length=22)

and after get_request() returns var_dump($data); displays this

array (size=2)  'id' => string '2' (length=1)  'skills' =>     array (size=3)      0 => string 'core java' (length=9)      1 => string 'advance' (length=7)      2 => string '.net' (length=4)

If you want to process more than one userid then you will need a bit more code. Let me know if you need to see that.