can you help... in Pagination I modified View and Controller function |
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')) ;
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/d...ching.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.
$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 ???
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/d...ching.html https://www.codeigniter.com/user_guide/l...sions.html
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); } } |
Welcome Guest, Not a member yet? Register Sign In |