我正在尝试为我的搜索结果添加分页。我很喜欢得到像你这样的网址。
localhost:81/profile/index.php/main/search?query=vi
我想要的是:
localhost:81/profile/index.php/main/search?query=vi&off=5
单击1,2,3分页链接时,使用偏移值。
<?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');
}}
?>
答案 0 :(得分:3)
If only CodeIgniter had a great user guide, and a pagination library.
看看上面的页面。然后,您需要根据URL中的参数筛选记录。
答案 1 :(得分:0)
检查此链接。在我使用代码以简短的方式从数据库中获取结果集后,我回答了如何进行分页。