我的网站主页上有一个搜索栏。当我搜索公司并单击“搜索”时,它会重定向到http://mydomain.com/searchresults页面。(注意:我使用 url 路由删除了控制器名称“home”)
我的网址中没有任何搜索词或结果。这只是一个干净的网址。
当我尝试在该页面中实现分页时,它不起作用,因为当我转到下一页时,搜索项消失了,它显示了我数据库中的所有公司。
如何在此页面添加分页?
我的控制器:
function searchresults()
{
$this->breadcrumbs->page = array('link'=> base_url().'home/search' ,'title' => 'Bedrijven Zoeken' );
$this->breadcrumbs->method = array('link'=> base_url().'home/searchresults' ,'title' => 'Zoekresultaten' );
$data['breadcrumbs'] = $this->breadcrumbs->get();
$match = $this->input->post('search');
if(strlen($this->input->post('cookie')) > 0){ $match2 = $this->input->post('cookie'); } else{ $match2 = '9101'; }
$data['query'] = $this->bedrijven_model->get_search($match, $match2);
$this->load->view('views/header');
$this->load->view('views/searchresults', $data);
$this->load->view('views/footer');
$data['query'] = $this->bedrijven_model->bedrijven_tags();
}
我的模型:
function get_search($match, $match2)
{
if (!isset($_COOKIE['cookie'])) {
$query = "SELECT * FROM (`bedrijfcategorieen`)
JOIN `bedrijven` ON `bedrijfcategorieen`.`idbedrijven` = `bedrijven`.`idbedrijven`
JOIN `categorieen` ON `bedrijfcategorieen`.`idcategorieen` = `categorieen`.`idcategorieen`
WHERE (`Bedrijfsnaam` LIKE '%".$this->input->post('search')."%'
OR `Plaats` LIKE '%".$this->input->post('search')."%'
OR `Telefoonnummer` LIKE '%".$this->input->post('search')."%'
OR `Email` LIKE '%".$this->input->post('search')."%'
OR `Website` LIKE '%".$this->input->post('search')."%'
OR `Profiel` LIKE '%".$this->input->post('search')."%'
OR `Adres` LIKE '%".$this->input->post('search')."%'
OR `Categorie` LIKE '%".$this->input->post('search')."%')
AND (Postcode LIKE '%".$this->input->post('cookie')."%')
GROUP BY `bedrijfcategorieen`.`idbedrijven`";
$result = $this->db->query($query);
return $result->result();
}
我的搜索页面:
<form name="input" action="searchresults" method="post">
<input type="search" onchange="validate()" placeholder="Zoeken..." name="search" size="70">
<input type="search" onchange="validate()" required="true" size="14" placeholder="Postcode..." name="cookie" value="<?= $this->input->cookie('postcode', TRUE); ?>" >
<input type="submit" value="Zoeken">
</form>
我的搜索结果页面:
<div id="bigcontent">
<h1>Companies found: <?= count($query); ?></h1>
<?= br(1); ?>
<h2>Company:</h2>
<?= br(1); ?>
<?= $this->pagination->create_links(); ?>
<?= br(2); ?>
<hr/>
<?php foreach($query as $item):?>
<a href="<?php echo base_url()?>bedrijven/<?= $item->idbedrijven?>"><h3><?= $item->Bedrijfsnaam ?></h3></a>
<p><b>Categorie:</b> <?= $item->Categorie ?></p>
<p><small><?php echo $item->Profiel ?></p>
<p><b><?php echo $item->Email ?></b></p>
<p><b>Postcode:</b> <?php echo $item->Postcode ?></p>
<p><b>Tags:</b></p>
</small>
<hr/>
<?php endforeach;?>
<br />
<<<a href="<?php echo base_url() ?>">Terug</a>
我试过类似的东西:
(我在我的 autoload.php 文件中加载了分页库)
$config['base_url'] = 'http://kees.een-site-bouwen.nl/home/searchresults';
$config['total_rows'] = $data['query'];
$config['per_page'] = 4;
$this->pagination->initialize($config);
但它没有用。
我希望很清楚我想要什么。