контроллер: Posts.php
Код: Выделить всё
class Post extends CI_Model {
function get_posts($num = 20, $start = 0) {
$this->db->select()->from('posts')->where('active', 1)->order_by('date_added', 'dec')->limit(0, 20);
$query = $this->db->get('posts');
return $query->result_array();
}
}
Код: Выделить всё
class Posts extends CI_Controller {
function index() {
$this->load->model('post');
$data['posts'] = $this->post->get_posts();
echo"
";print_r($data['posts']);echo"";
}
}
Код: Выделить всё
Array
(
)
Код: Выделить всё
+------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------------+-----------------------------+
| postID | int(10) | NO | PRI | NULL | auto_increment |
| title | varchar(255) | NO | | NULL | |
| post | text | NO | | NULL | |
| date_added | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| userID | int(4) | NO | | NULL | |
| active | tinyint(1) | NO | | NULL | |
| slug | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+-------------------+------------------
Подробнее здесь: https://stackoverflow.com/questions/220 ... ters-limit
Мобильная версия