0

I am trying to show my table in pagination.Links are coming but when i click on a 2 or 3 or anything it goes to /view_expenses/view&per_page= this. and i ll get a 404 error.why its not showing the rest data?

This is my controller

class View_expenses extends CI_Controller
 {
    public function __construct()
    {
        parent::__construct();
        $data['title']= 'View Expenses';
        $this->load->view('header_view',$data);
        $this->load->model('emp_expenses_model');
        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->load->library('pagination');                 
            }


    public function index()
    {


            }
    function view($offset=0){
        $limit=5;
        //$this->uri->segment(3);
        $this->load->model('emp_expenses_model');
        //$result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
        $result['countRows']=$this->emp_expenses_model->countRows();
        $this->load->library('pagination');
        $this->load->library('table');
        $config=array(
                        'base_url' =>site_url ('/view_expenses/view'),
                        'total_rows' => $result['countRows'],
                        'per_page' => $limit,
                        'uri_segment' => 3,
                        'num_links' => 1,
         );  
         //var_dump($config); 
        $this->db->limit(5);
        $this->pagination->initialize($config);
        $this->load->model('emp_expenses_model');
        $this->data['view_expenses'] = $this->emp_expenses_model->get_all();
        //$this->data['pagination'] = $this->pagination->create_links();
        //var_dump($this->data['pagination']);die("jk");
        $this->data['title'] = 'Payroll System';
        $this->data['message'] = $this->session->flashdata('message');
            $this->load->library('pagination');
        $this->load->view('view_expenses', $this->data);
        /*$this->load->view('add_list', $this->data);*/

    }   

This is my model

function getRows($limit,$offset)
    {
    $query=$this->db->select('expenses_id,id,dropdown,modeofpayment,amount')
           ->from('emp_expenses')
           ->limit($limit,$offset);
    $result=$query->get()->result_array();
    return $result;
    //var_dump($result);
    }
    function countRows()
    {
    //$query="select count(*) as count from emp_expenses";
    $result = $this->db->count_all_results('emp_expenses');
    //$result=$this->db->query($query);
    return $result;
    //var_dump('countRows');
}

This is My View

   <table cellspacing="0" cellpadding="2" border="0" id="tbl"  style="width:100%">
<tr style="background-color:#045c97">
 <?php echo $this->pagination->create_links()?>
  <td class="heading">Employee ID</td>
  <td class="heading">Drop Down</td>
  <td class="heading">Mode OF Payment</td>
  <td class="heading">Amount</td>
  <td class="heading">Edit</td>
  <td class="heading">Delete</td>
</tr>
<?php
foreach ($view_expenses as $m){
  $list_id = $m['id'];
  //print_r($list_id);die('adad');
  //$m['username']='';
?>
  <tr style="text-align:center;">
      <td><?php echo $m['id'] ?></td>
    <td><?php echo $m['dropdown'] ?></td>
            <td><?php echo $m['modeofpayment'] ?></td>
             <td><?php echo $m['amount'] ?></td>
    <td><a href="<?php echo site_url('view_expenses/edit_expenses/'.$list_id) ?>"class="btn btn-primary btn-mini">Edit</a></td>
    <td>
      <?php 
        echo anchor('view_expenses/delete_expenses/'.$list_id, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
      ?>
    </td>
4

2 回答 2

1

您需要使用?not&将查询字符串与请求的其余部分分开

于 2013-08-12T11:08:00.370 回答
1

您的查询完全错误,您必须在 URL 中的所有其他内容之前添加一个问号。

 foo://example.com:8042/over/there?name=ferret&color=brown#nose
 \_/   \______________/\_________/ \______________________/ \__/
  |           |            |            |                    |
scheme     authority       path        query              fragment

请注意,“问号”或查询运算符必须位于任何查询之前,但如果有多个查询,则应使用“&”分隔。

尝试这个:

/view_expenses/view?per_page=

至于没有向您显示您想要的链接,您的代码无论如何都不正确。这是一个我觉得很容易理解的教程: http ://www.phpfreaks.com/tutorial/basic-pagination

于 2013-08-12T11:18:29.327 回答