也許是因爲睡眠不足我的邏輯有一些問題。 在CodeIgniter中,我需要從數據庫中獲取最後10個帖子並將其顯示在頁面上。CodeIgniter:從DB返回並顯示多行
我的控制器如下:
public function index() {
// $data is an array containing some useless stuff like title, etc.
// Never mind.
// Skipped header & navbar view loaders;
$this->load->view('blog_page', $data);
$this->get_latest_posts(1);
}
現在的模型有云:
public function get_latest_posts($i) {
// $i is a number of posts to be displayed. Now it is 10
$query = $this->db->get('posts', $i);
return $query->result();
// Any clue what to do here, cause I need an array that contains arrays of post rows;
}
我一直試圖做一個foreach循環,但使用一排時,它僅適用; 我會感謝您的幫助,夥計們!
每個答案都會對每個小貓在星球上的生活產生積極的影響。
P.S.我從我的代碼中刪除了任何不必要的東西,如加載頁眉&頁腳視圖。
睡一覺。 – Gordon 2015-04-04 11:49:04