Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter count_all for pagination

I'm trying to create pagination in codeigniter and I have it working, but I have a small issue. It seems to be loading all the entries in my database and not the selected ones I want.

public function original_count() {
     $this->db->where('type', 'Original');
      return $this->db->count_all("story_tbl");
    }

I know that whats happening is that the last line is overrighting my previous statements. I can't seem to find a way around it though. I tried just a staight sql statement and then returning it, but I could not get that to work either.

this was my statement...

SELECT COUNT(*) FROM story_tbl where type = 'Original';

Some help would much appreciated! :)

like image 363
zazvorniki Avatar asked Nov 28 '22 02:11

zazvorniki


1 Answers

CI has inbuilt count method

count_all_results()

Permits you to determine the number of rows in a particular Active Record query. Queries will accept Active Record restrictors such as where(), or_where(), like(), or_like(), etc. Example:

https://www.codeigniter.com/userguide2/database/active_record.html

$total_count = $this->db->count_all_results('story_tbl', array('type' =>'Original'));
like image 191
Dino Babu Avatar answered Dec 05 '22 23:12

Dino Babu