[eluser]Otemu[/eluser]
Hi,
I have two calls to the model class for my pagination to work, but I was wondering if I could get this down to just one function.
The first function queries the database and returns the number of rows
Code:
function getNewsAllN() {
$data = array();
$this->db->select('articles.articleid as newsid, articles.template, articles.intro_text, articles.page_title, articles.page_url, articles.display, images.articleid, images.imageurl, images.description');
$this->db->from('articles', 'images');
$this->db->join('images', 'articles.articleid = images.articleid','left');
$this->db->where('articles.parentid', 2);
$this->db->where('articles.template', 'default_article');
$this->db->where('articles.display', 'yes');
$Q = $this->db->get();
$total = $Q->num_rows();
$data = $total;
$Q->free_result();
return $data;
}
and the second function queries the database and returns the rows.
Code:
function getNewsAll($num, $offset) {
$data = array();
$this->db->select('articles.articleid as newsid, articles.template, articles.intro_text, articles.page_title, articles.page_url, articles.display, images.articleid, images.imageurl, images.description');
$this->db->from('articles', 'images');
$this->db->join('images', 'articles.articleid = images.articleid','left');
$this->db->where('articles.parentid', 2);
$this->db->where('articles.template', 'default_article');
$this->db->where('articles.display', 'yes');
$this->db->limit($num);
$this->db->offset($offset);
$Q = $this->db->get();
$Q->num_rows();
if ($Q-> num_rows() > 0){
foreach ($Q-> result_array() as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
The Controller then uses both these functions for my pagination to work
Code:
$numrows = $this->M_Articles->getNewsAllN();
$config['total_rows'] = $numrows;
$data['records'] = $this->M_Articles->getNewsAll($config['per_page'],$this->uri->segment(3));
is it possible some how to narrow this just to one function call?