如何使用php - codeigniter中的cookie值进行搜索 [英] How to search with the value of a cookie in php - codeigniter

查看:111
本文介绍了如何使用php - codeigniter中的cookie值进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次访问时有一个弹出对话框。您可以使用半径设置邮政编码。 onsubmit设置并显示在主网页上:

I have a popup dialog on first visit. you can set the postcode with a radius. onsubmit the cookies are set and shown on the main webpage:

您可以在这里尝试: http://kees.een-site-bouwen.nl

现在您看到一个searchform,用于在我的数据库。我的工厂表格如下:

Now you see a searchform for searching factories in my database. my factories table looks like this:

Factories
- - - - - 
idfactories
factoryname
postcode
place
telephonenumber
email
website
profile
adress

注意我在表中有一个postcode字段。那么如何使用我使用Cookie设置的邮政编码在该表格中进行搜索?

note i have a postcode field in my table. so how do i search in that table using the postcode i set using cookies?

我的设置Cookie代码:

my code for setting the 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"])) {
}
?>

我的模型中的搜索查询:

My searchquery in my model:

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-& > cookie('search'); 但不起作用

推荐答案

t请参阅您使用swarch键保存Cookie的位置。我只看到邮政编码和半径。然后你必须检索如

First I don't see where you save your cookie with key "swarch". I see postcode and radius only. Then you have to retrieve the cookie like

$this->input->cookie('postcode')

无论如何,如果您正在设置正确的cookie。

Anyway if you are setting the correct cookie. Are you loading the cookie helper?

$this->load->helper('cookie');

干杯!

这篇关于如何使用php - codeigniter中的cookie值进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆