我目前正在構建codeigniter的網站上,目前我正在查詢數據,我認爲可能有3個數組可以作爲數組返回不同的結果的量,我的問題我不能爲我遍歷數組我此刻的生活,通過多維數組的PHP循環
我的模型看起來像這樣
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();
}
我控制器
enter public function index() {
// $this->output->enable_profiler(TRUE);
$data = 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 = array_merge($data, $image);
die(print_r($data));
$this->load->view('home/main_page.php', $data);
}
的獲取返回數組看起來像這樣,
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
你說的意思*我不能在此刻我遍歷數組我的生活*。你不知道如何使用foreach?你不知道如何遍歷多維數組?你有沒有工作的代碼?請更具體地說明你的問題。 – Gordon 2010-01-06 17:00:43