如何添加分页到这里 [英] how to add pagination to this
本文介绍了如何添加分页到这里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的查看页面上的搜索结果添加分页。我非常困惑得到的URL像..
localhost:81 / profile / index.php / main / search? query = vi
我想要的是:
localhost:81 / profile / index.php / main / search?query = vi& off = 5
$点击1,2,3分页链接时,p $ p>
。
<?php if(!defined('BASEPATH'))exit('不允许直接脚本访问);
class Main extends CI_Controller {
function index()
{
$ this-> load-> ; view('main_view');
}
function search()
{
$ off = $ _GET ['off'];
$ query = $ _GET ['query'];
$ min_length = 1;
if(strlen($ query)> = $ min_length)
{
$ query_str =SELECT * FROM customers WHERE customerName LIKE' %$ query%'LIMIT 10 OFFSET'$ off';
echo $ query_str;
$ result = $ this-> db-> query(SELECT * FROM customers WHERE customerName LIKE'%$ query%'LIMIT 10 OFFSET $ off) - > result_array();
echo< table border ='1'cellpadding ='10'>;
echo< tr>< th>号< / th>< th>名< / th>< th地址< / th>< th>电话< / th>< / tr ;;
foreach($ result as $ data)
{
echo< tr>< / tr>;
echo< td>。$ data ['customerNumber']。< / td>。< td>。$ data ['customerName']。< / td& 。< td>。$ data ['addressLine1']。< / td>。
< td>。$ data [phone]。< / td>;
}
}
else
{
echo最小长度为$ min_length;
}
$ this-> load-> view('main_view');
}}
?>
解决方案如果只有CodeIgniter有一个伟大的用户指南和分页库。
查看上面的页面。然后,您希望在根据网址中的参数选择记录时过滤记录。
I'm trying to add pagination to my search results I get on my view page. I'm pretty much confused with getting url like..
localhost:81/profile/index.php/main/search?query=vi
What i'm trying to get is:
localhost:81/profile/index.php/main/search?query=vi&off=5
with the offset value, when clicked on 1,2,3 pagination links.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Main extends CI_Controller{ function index() { $this->load->view('main_view'); } function search() { $off = $_GET['off']; $query = $_GET['query']; $min_length = 1; if(strlen($query) >= $min_length) { $query_str = "SELECT * FROM customers WHERE customerName LIKE '%$query%' LIMIT 10 OFFSET '$off'"; echo $query_str; $result = $this->db->query("SELECT * FROM customers WHERE customerName LIKE '%$query%' LIMIT 10 OFFSET $off")->result_array(); echo "<table border='1' cellpadding='10'>"; echo "<tr><th>Number</th><th>Name</th><th>address</th><th>phone</th></tr>"; foreach($result as $data) { echo "<tr></tr>"; echo "<td>".$data['customerNumber']."</td>"."<td>".$data['customerName']."</td>"."<td>".$data['addressLine1']."</td>". "<td>".$data["phone"]."</td>"; } } else { echo "Minimum length is ".$min_length; } $this->load->view('main_view'); }} ?>
解决方案If only CodeIgniter had a great user guide, and a pagination library.
Take a look at the above page. You then want to filter your records when selecting them based on the parameters in the URL.
这篇关于如何添加分页到这里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文