Pagination with database

In your controller make method like below:
note: Here i am creating a pagination with a date between query, so keep clam and read.


public function fn_name(){
        $fdate=$this->uri->segment(3); //getting date from url
        $tdate=$this->uri->segment(4);
        if($fdate!=”” && $tdate!=””){
            $config[“base_url”]=base_url().’controller/method/’.$fdate.’/’.$tdate;
            $config[“total_rows”]=$this->Model->total_row_fn_name($fdate,$tdate);
            $config[“per_page”] = 6;
            $config[“uri_segment”] = 5;
            $choice = $config[“total_rows”] / $config[“per_page”];
            $config[“num_links”] = round($choice);
            $this->pagination->initialize($config);
            $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
            $result[“data”] = $this->Model->method_Bydate($config[“per_page”],$page,$fdate,$tdate);
            $result[‘pagination_link’]=$this->pagination->create_links();
        }
        $this->load->view(‘pages/slip_report’,$result);

    }

In your model make a method:


public function total_row_fn_name($fdate,$tdate){
        $sql=$this->db->select(‘put your database field to select here’)
            ->join(‘tbl name’,’table.field=tbl.field’,’left’)
            ->join(‘tbl’,’tbl.field=tbl.field’,’left’)
            ->where(‘DATE(chalan_date) >=’,date(‘Y-m-d’,strtotime($fdate)))
            ->where(‘DATE(chalan_date) <=’,date(‘Y-m-d’,strtotime($tdate)))
            ->order_by(‘tbl.field’)
            ->get(‘tbl’);
        return $sql->num_rows();
    }

public function method_Bydate($limit,$start,$fdate,$tdate){
        $sql=$this->db->select(‘ your fields goes here’)
            ->join(‘tbl’,’tbl.field=tbl.field’,’left’)
            ->join(‘tbl’,’tbl.field=tbl.field’,’left’)
            ->where(‘DATE(date_field) >=’,date(‘Y-m-d’,strtotime($fdate)))
            ->where(‘DATE(date_field) <=’,date(‘Y-m-d’,strtotime($tdate)))
            ->order_by(‘field’)
            ->limit($limit,$start)
            ->get(‘dailycirculation’);
        //echo $this->db->last_query();
        return $sql->result_array();
    }

In your view invoke this pagination like below:


<?php echo $pagination_link;?>

Create new user type in gocart

first go to views -> admin -> admin_forms.php file.

go to near this lines: ‘Admin’, ‘Orders’ => ‘Orders’, ‘Software_op’=>’Software Operator’ );

echo form_dropdown(‘access’, $options, set_value(‘phone’, $access)); ?>

* after adding your user like mine, i have added software operator. you will see in this list in your admin panel.

—————————————————————————–

Now you have do some Auth works in your header.php file and those pages you want to restrict.

like here my software operator will see only catalog’s categories and products pages in their admin panel.

in dashboard.php file comment these below lines:

// if($this->auth->check_access(‘Orders’)){

// redirect($this->config->item(‘admin_folder’).’/orders’);

// }

Now go to categories.php controller file and add these lines:

$this->CI =& get_instance();

$admin = $this->CI->session->userdata(‘admin’);

$access=$admin[‘access’];

//$this->auth->check_access(‘Admin’, true);

$this->auth->check_access($access, true);

*** note: you must comment this line on your controller file:

//$this->auth->check_access(‘Admin’, true);

You are done!

Search query [multiple where condition in a tiny code]

codeigniter search query [multiple where condition in a tiny code] *return single row
in controller:
$wc=array(
         ‘table_field1’  =>  $where_value,
         ‘table_field2’  =>  $where_value
); //whatever conditions you can apply here



$product_price=$this->Model->getTableData(‘wp_postmeta’,$wc,’field_name’);


in model:
public function getTableData($tableName,$whereCondition,$tableField){
        $query = $this->db->get_where($tableName,$whereCondition);    
              $res=$query->row_array();
              return $res[$tableField];

    }


——————————————————————————————————
codeigniter search query [multiple where condition in a tiny code] *return multi row
in controller:
$wc=array(
         ‘table_field1’  =>  $where_value,
         ‘table_field2’  =>  $where_value
); //whatever conditions you can apply here



$product_price=$this->Model->getTableData(‘wp_postmeta’,$wc);


in model:
public function getTableData($tableName,$whereCondition){
        $query = $this->db->get_where($tableName,$whereCondition);        
              $res=$query->result_array();
              return $res;

    }