我试图在分页中显示我的表。链接即将到来,但当我点击2或3或其他任何内容时,它会转到 / view_expenses / view& per_page = 这个。然后我会收到404错误。为什么它没有显示其余数据?
这是我的控制器
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);*/
}
这是我的模特
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');
}
这是我的观点
<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>
答案 0 :(得分:1)
您需要使用?
而非&
将查询字符串与其余请求分开
答案 1 :(得分:1)
您的查询写得完全错误,您必须在网址中的其他所有内容之前加上问号。
foo://example.com:8042/over/there?name=ferret&color=brown#nose
\_/ \______________/\_________/ \______________________/ \__/
| | | | |
scheme authority path query fragment
请注意,“问号”或查询运算符必须在任何查询之前出现,但如果有多个查询,则应由“&amp;”分隔。
试试这个:
/view_expenses/view?per_page=
对于没有显示您想要的链接,您的代码无论如何都不正确。这是一个我很容易理解的教程: http://www.phpfreaks.com/tutorial/basic-pagination