![]() |
can you help... in Pagination I modified View and Controller function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: can you help... in Pagination I modified View and Controller function (/showthread.php?tid=71052) Pages:
1
2
|
RE: can you help... in Pagination I modified View and Controller function - lsepolis123 - 07-03-2018 As you say in Post #2 above public function page() { $this->load->library('pagination'); $config['base_url'] = base_url('admin/ads/page'); $config['total_rows'] = $this->db->count_all('videos'); having 1 2 3 4 5 next> pages changing Page will run again page() ... ? if yes this isset() check should faster the function if run only for first time ? if having $config['total_rows'] = $this->db->count_all('video') each time this will run again and again slowing the function... ? so required the >> // ??? isset($config['total_rows']) ? '' : ($config['total_rows'] = $this->db->where('public',1)->count_all('videos')) ; RE: can you help... in Pagination I modified View and Controller function - jreklund - 07-03-2018 Every time you visit /page/1, /page/2 etc... it will run page() again. At every run $config['total_rows'] won't be set, so it will still run that query. You need to use database cache or store it in sessions in case you don't want it to load it from the database. https://www.codeigniter.com/userguide3/database/caching.html But then you need to delete all cache files every time a video are uploaded. This query shouldn't take more than a couple of microseconds or so. It's not like you are making a new Youtube. RE: can you help... in Pagination I modified View and Controller function - lsepolis123 - 07-03-2018 ok thks RE: can you help... in Pagination I modified View and Controller function - lsepolis123 - 07-04-2018 $this->db->where('public',1)->count_all('videos') ; checked this DOES NOT WORK getting all even public=1 no importance well how count only one when first page called ??? RE: can you help... in Pagination I modified View and Controller function - jreklund - 07-04-2018 Okey, never actually tested it. Just thought you could chain them together. Here are one that works. PHP Code: $config['total_rows'] = $this->db->query('SELECT count(*) as total_rows FROM `videos` WHERE `public`=1')->row()->total_rows; You can save the results with either database cache (flat files) or local sessions (not recommended, as users will get from count, as new ones comes in). https://www.codeigniter.com/user_guide/database/caching.html https://www.codeigniter.com/user_guide/libraries/sessions.html RE: can you help... in Pagination I modified View and Controller function - alamowais - 07-24-2018 you can use the logic in controller class Welcome extends CI_Controller { public function __construct() { parent:: __construct(); $this->load->helper("url"); $this->load->model("Departments"); $this->load->library("pagination"); } public function departmentdata() { $config = array(); $config["base_url"] = base_url() . "welcome/departmentdata"; $config["total_rows"] = $this->Departments->record_count(); $config["per_page"] = 5; $config["uri_segment"] = 3; $this->pagination->initialize($config); $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $data["results"] = $this->Departments-> fetch_departments($config["per_page"], $page); $data["links"] = $this->pagination->create_links(); $this->load->view("departmentdata", $data); } } |