【问题标题】:codeigniter pagination next link not displaying record from databasecodeigniter 分页下一个链接不显示数据库中的记录
【发布时间】:2014-09-15 06:16:01
【问题描述】:

我是 CI 新手,所以请大家帮我显示分页链接的结果。在数据库中,我有 3 条记录,每页显示一条记录。

当我选择下一个分页结果的数字链接时,问题出在我的分页链接中。

问题是,当我单击分页链接输出的第 2 号时,显示 $results 为空,并且我没有得到 echo $data->email 的任何值。

我也无法通过谷歌得到答案但是当页面加载的问题是当我选择下一个数字链接的分页链接时显示一条记录它不起作用。 分页脚本无法正常工作,我认为它与偏移量有关。

这是我的控制器。

public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
            {
return $this->db->query("SELECT *FROM users WHERE   gender = '$look' And status='1'")->result();
            }  

所以我不确定可能是什么错误,所以我在下面发布我的代码,请仔细阅读并帮助我。

**Here is my view page**

if (empty($results)) {
    echo 'Results set is empty';
} else {
foreach ($results as $data) {
        echo $data->email.'<br />';
    }
}
echo $pagination_links;

//Error is when i select next numeric link of pagination record is not being fetched from database getting output as emty result in my view page.so request you to help me in solving the issue and more warning message is  missiing argument 2 for Searchresult::users() , and more errror message is undefined variable offset .

【问题讨论】:

  • 你必须通过所有参数进行分页$config['base_url'],在加载页面时传递这些参数,也粘贴你的分页代码。
  • $config['base_url'] = base_url().'searchresult/users/$look/$age/$age_to/$age_from/$se_ct/$subsect/$coun_try/$sta_te/$ ci_ty/$qualification';
  • //您提交的 URI 包含不允许的字符。我得到的错误是什么
  • 还需要设置offset和Limit,请检查codeigniter pagination,粘贴你的controller,model函数。
  • Reena 的问题仍然存在

标签: php codeigniter pagination


【解决方案1】:

首先,没有必要传递 100 个你甚至不使用的参数,去掉那些。

现在是代码。

function login($look, $page = 0, $offset = 1){
    $query = $this->db->get_where('users', array('gender' => $look, 'status' => '1'), $limit, $offset);
    return $query;
}

应该可以的。

【讨论】:

  • 我正在使用这些参数..事情是我缩短了我的查询,这就是它
  • 执行 print_r($this->db->get('users'));返回什么?
  • 是的,如果我将模型更改为公共函数登录($look,$age,$age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te,$ci_ty,$qualification){ $query = $this->db->get("users"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $data[] = $row; } 返回$数据; } } 得到与我在问题中发布的相同的问题
  • 看起来您需要清理您的 URL,而不是像我想的那样,需要修复您的数据库,但我看错了地方,因为您没有在问题中告知我们您确实删除了某些内容从您的查询。如果您遗漏了可能会导致下次出现问题的内容,请记住通知:)
  • 哦,我非常抱歉...如何解决我可能出错的问题
【解决方案2】:

第一个分页配置:-

   $config['base_url'] = base_url() . 'controller_name/function_name/';
   $config['per_page'] = 20;    //lets say 20 record per page 
   $config['total_rows'] = $total_rows;
   $this->pagination->initialize($config);

根据分页配置从数据库中获取数据

  $start = $this->uri->segment(3, 0);
  $queryNum = $this->db->get('table_name');
    $num = $queryNum->num_rows();
    if ($num > 0) {
        $config['total_rows'] = $num; //reset total rows

        $this->db->limit($config['per_page'], $start);
        $queryNum1 = $this->db->get('table_name');
        foreach ($queryNum1->result() as $rows) {
            $tmp[] = $rows; //holds the query result data
        }
     }
    $data1['pagination'] = $this->pagination->create_links();

【讨论】:

    猜你喜欢
    • 2010-11-23
    • 1970-01-01
    • 2017-12-01
    • 2017-01-11
    • 2015-06-13
    • 2020-09-04
    • 2013-04-08
    • 2013-04-07
    • 2013-05-03
    相关资源
    最近更新 更多