我正在尝试将分页添加到我在查看页面上获得的搜索结果中。我对获取像这样的网址感到非常困惑。
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');
}}
?>