第一次访问时我有一个弹出对话框。您可以使用半径设置邮政编码。onsubmit cookie 被设置并显示在主网页上:
你可以在这里试试这个:http: //kees.een-site-bouwen.nl
现在您会在我的数据库中看到一个用于搜索工厂的搜索表单。我的工厂表如下所示:
Factories
- - - - -
idfactories
factoryname
postcode
place
telephonenumber
email
website
profile
adress
请注意,我的表中有一个邮政编码字段。那么如何使用我使用 cookie 设置的邮政编码在该表中搜索?
我设置cookie的代码:
<form method="post" action="">
<input type="text" name="postcode" placeholder="postcode">
<select name="radius">
<option disabled selected>Afstand</option>
<option>5km</option>
<option>10km</option>
<option>15km</option>
<option>25km</option>
</select>
<br /><br />
<input type="submit" value="Opslaan">
<input type="hidden" name="submitted" value="true">
<input type="hidden" name="afstand" value="true" />
</form>
<?php
if(isset($_POST['postcode']))
{
setcookie('postcode', $_POST['postcode'], time() + (20 * 365 * 24 * 60 * 60));
setcookie('radius', $_POST['radius'], time() + (20 * 365 * 24 * 60 * 60));
header("location: {$_SERVER['PHP_SELF']}");
};
?>
<?php
if (isset($_POST["set_radius"])) {
}
?>
我的模型中的搜索查询:
function get_search($match)
{
$this->db->like('Bedrijfsnaam', $match);
$this->db->or_like('Postcode', $match);
$this->db->or_like('Plaats', $match);
$this->db->or_like('Telefoonnummer', $match);
$this->db->or_like('Email', $match);
$this->db->or_like('Website', $match);
$this->db->or_like('Profiel', $match);
$this->db->or_like('Adres', $match);
$this->db->or_like('Categorie', $match);
$this->db->join('bedrijven', 'bedrijfcategorieen.idbedrijven = bedrijven.idbedrijven');
$this->db->join('categorieen', 'bedrijfcategorieen.idcategorieen = categorieen.idcategorieen');
$this->db->group_by('bedrijfcategorieen.idbedrijven', 'bedrijfcategorieen.idcategorieen');
$query = $this->db->get('bedrijfcategorieen');
return $query->result();
}
我的控制器功能:
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');
$data['query'] = $this->bedrijven_model->get_search($match);
$this->load->view('views/header');
$this->load->view('views/searchresults', $data);
$this->load->view('views/footer');
$data['query'] = $this->bedrijven_model->bedrijven_tags();
}
我尝试使用$this->input->cookie('search');
但没有用