【问题标题】:Codeigniter: Pagination doesn't get other rowsCodeigniter:分页没有其他行
【发布时间】:2014-10-26 11:00:52
【问题描述】:

我的控制器:

 $config['base_url'] = base_url('admin/profile?id=' . $profile_id);
  $config['total_rows'] = 1000;//count($data['getTime']);
  $config['per_page'] = 5; 
  $config['num_links'] = 2;
  //$config['uri_segment'] = 2;
  //$config['enable_query_strings'] = TRUE;
  $config['page_query_string'] = TRUE;
  $config['use_page_numbers'] = TRUE;
  $config['full_tag_open'] = '<div id="pagination">';
  $config['full_tag_close'] = '</div>';

  $this->pagination->initialize($config);

  $page = ($this->uri->segment(5))? $this->uri->segment(5) : 0;
  $data['getTime'] = $this->admin->getUserProfileTime($profile_id, $config["per_page"], $page);
  $data["links"] = $this->pagination->create_links();
  //pagination

我的模型

  function getUserProfileTime($profile_id, $num, $page)
{
$this -> db -> select('*');
//$this -> db -> from('timerecord');
$this -> db -> where('id', $profile_id);
//-$this -> db -> order_by('dateToday', 'DESC');
$this -> db -> order_by('dateOrder', 'DESC');
$this -> db -> limit($num, $page);

$query = $this -> db -> get('timerecord');
//$array = $query->result_array();
return $query->result();

if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;

}

我的观点

 <?php 
                foreach($getTime as $row): 
                $timeStat = $row->status;
                $approveStat = $row->ApprovalStat;
              ?>
              <tr>
                <td class="tn-ixdt"><?php echo $row->year_Int ?></td>
                <td class="tn-ixdt"><?php echo $row->dateToday ?></td>
                <td class="tn-ixdt"><?php echo $row->day ?></td>
                <td class="tn-ixdt" style="text-align:center;"><?php echo $row->day_Int ?></td>
                <td class="tn-ixdt"><?php echo $row->timeIn ?></td>
                <td class="tn-ixdt"><?php echo $row->timeOut ?></td>
                <td class="tn-ixdt"><?php echo $row->status ?></td>
              </tr>
              <?php endforeach; ?>
              </table><br />
            <div align="center"><?php echo $links; ?></div>

您好,我的分页工作不正常,它显示了前 5 个正确的记录,但是当我单击分页链接时,它没有转到其他行,是我的 url 查询中的问题吗?我的 url 就像这个 admin/profile?id=1&per_page=65,页码也是正确的,但它仍然没有从我的表中获取其他记录。拜托,我需要你们的帮助!谢谢!

【问题讨论】:

  • 尝试打印在您点击下一页时构建的原始查询,看看那里有什么问题
  • 构建原始查询是什么意思?先生。呸呸呸?
  • 来自您的活动记录的原始查询
  • 嗨,先生。 ngakak,我认为这是 uri 段的错误,因为当我将 $page 更改为数字“1”时,它可以完美地工作,请检查代码。谢谢,如果你能回答这个痛苦,我会非常感谢你 mr.ngakak $page = ($this->uri->segment(2))? $this->uri->segment(2) : 0; $data['getTime'] = $this->admin->getUserProfileTime($profile_id, $config["per_page"], 1);
  • 这个 $page = ($this->uri->segment(5)) 的结果是什么? $this->uri->segment(5) : 0;每次你点击下一页?如果 smth 错了,那就是问题所在

标签: php mysql codeigniter pagination


【解决方案1】:

因为您使用了错误的表.. 尝试将其添加到您的控制器中

$this->load->library('table');

在你看来,看看你的桌子..这是代码

$this->table->set_heading('header1', 'header2', 'header3','header4'); //this is just the table heading

//in this code, you are looping your table row and the database informatio
    foreach ($products->result() as $row) { 


        $this->table->add_row(
            $row->column1,
            $row->column2,
            $row->column3,
            $row->column4
        );
    }


    echo $this->table->generate();

你的模型的这段代码,去掉->result(),应该是

    foreach ($query as $row) {
        $data[] = $row;
    }

【讨论】:

  • 先生还是不走运。代码层,这里是输出
  • 不要把输出放在这里..编辑你的答案并添加输出..在你完成编辑后在这里评论通知我
猜你喜欢
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 2019-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多