PHP loop through multi-dimensional array

rohitdrigger

New Member
I am currently working on a site that is being built on codeigniter, I am currently querying the data at the moment I think there could be possible 3 arrays that could be returned as array each with a varying amount of results, my question I cannot for life of me loop through the array I have at the moment, my model looks like this\[code\]public function get_special_backgrounds() { $this->db->select('*'); $this->db->from('background'); $this->db->where('is_special', 1); $query = $this->db->get(); return $query->result_array();}\[/code\]my controller\[code\]enter public function index() {// $this->output->enable_profiler(TRUE); $data = http://stackoverflow.com/questions/2014608/array(); if($query = $this->category_model->get_all_online()) { $data['main_menu'] = $query; } $this->load->model('image_model'); /* * Sort out the users backgrounds, basically do a check to see if there is a 'special' background * if there is not a 'special' background then IF the user is logged in and has a background of there * own show that one, if not show a generic one, if they are not logged in show a generic one */ $image = array(); if ($query = $this->image_model->get_special_backgrounds()) { $image = $query; } $data = http://stackoverflow.com/questions/2014608/array_merge($data, $image); die(print_r($data)); $this->load->view('home/main_page.php', $data);}\[/code\]the array the gets return looks like this,\[code\]Array( [main_menu] => CI_DB_mysql_result Object ( [conn_id] => Resource id #28 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 1 [row_data] => ) [special] => Array ( [0] => Array ( [background_id] => 6 [background_name] => Master-Backgrounds.png [background_path] => /Users/Simon/Sites/mysite/media/uploads/backgrounds/ [is_special] => 1 [background_date_uploaded] => 1262687809 [users_user_id] => 1 [users_user_group_group_id] => 1 ) [1] => Array ( [background_id] => 11 [background_name] => Master-mysite-Template.png [background_path] => /Users/Simon/Sites/mysite/media/uploads/backgrounds/ [is_special] => 1 [background_date_uploaded] => 1262795313 [users_user_id] => 5 [users_user_group_group_id] => 2 ) ))1\[/code\]
 
Back
Top