问题描述
我有一个搜索功能,使用您的邮政编码搜索工厂。
这是基于我今天早些时候问的问题:
我有这样的查询:
这很好,但当我添加:
code> $ match = $ this-> input-> cookie('postcode');
它覆盖了第一个$ match。
如何设置两个变量如$ match1和$ match2?当我做它只搜索工厂,而不是邮政编码。我只想得到邮政编码和搜索工厂的结果,其邮政编码为9101例如
我的模型功能:
function get_search($ match,$ match2)
{
$ 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');
$ match2 = $ this-> input-> cookie('postcode');
$ 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')。%'
或`telefoonnummer` LIKE '%'。$ this-> input-> post('search')。%'
或`Email` LIKE'%。$ this-> input-& )%'
OR`Website` LIKE'%。$ this-> input-> post('search')。%'
OR`Profiel`LIKE'%。 $ this-> input-> post('search')。%'
OR`Adres` LIKE'%。$ this-> input-> post '
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();
}
这种方式搜索两件事。
我的控制器:
function search()
{
$ this-> breadcrumbs-> page = array('link'=> base_url()。'home / search' ,'title'=>'Bedrijven Zoeken');
$ data ['breadcrumbs'] = $ this-> breadcrumbs-> get();
$ this-> load-> view('views / header');
$ this-> load-> view('views / search',$ data);
$ this-> load-> view('views / footer');
}
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();
}
我的意见:
搜索:
< div style =clear:both; margin-top:10px ;>< / div>
$ c $ p>
< div class =path><?php echo $ breadcrumbs?>< / div>
< div id =bigcontent>
< h1> Bedrijven zoeken< / h1>
< hr>
< br />
< br />
< p> Voer een zoekterm en postcode in om bedrijven te zoeken。< / p>
< br />
< form name =inputaction =searchresultsmethod =post>
< input type =searchonchange =validate()placeholder =Zoeken ...name =searchsize =70>
< input type =searchonchange =validate()required =truesize =14placeholder =Postcode ...name =cookievalue =<?= $ this-> input-> cookie('postcode',TRUE);?> >
< input type =submitvalue =Zoeken>
< / form>
< br />< br />
< form method =linkaction =<?= base_url('bedrijven / all')?>>
< input type =submitvalue =Alle bedrijven>
< / form>
< / div>
搜索结果:
< div style =clear:both; margin-top:10px;>< / div&
< div class =path><?php echo $ breadcrumbs?>< / div>
< div id =bigcontent>
< h1> Bedrijven gevonden:<?= count($ query); ?>< / h1>
<?= br(1); ?>
< h2> Bedrijf:< / h2>
<?= br(1); ?>
< hr />
<?php foreach($ query as $ item):?>
< a href =<?php echo base_url()?> bedrijven /<?= $ item-> idbedrijven?>>< h3& > Bedrijfsnaam?>< / h3>< / a>
< p>< b>分类:< / b> <?= $ item->分类?>< / p>
< p>< small><?php echo $ item-> Profiel?>< / p>
< p>< b><?php echo $ item->电子邮件?>< / b>< / p&
< p>< b>邮政编码:< / b> <?php echo $ item->邮政编码?>< / p>
< p>< b>标签:< / b>< / p>
< / small>
< hr />
<?php endforeach;?>
< br />
<<< a href =<?php echo base_url()?>> Terug< / a>
< / div>
I have a searchfunction for searching factories using your postcode.
this is based on a question i asked earlier today: How to search with the value of a cookie in php - codeigniterI have a query like this:
this is working fine but when i add:
$match = $this->input->cookie('postcode');
it's overriding the first $match. how can i use both searchqueries without overriding eachother?
How do i set two variables like $match1 and $match2? when i do that it searches on factories only and not on postcode. i just want to have results of postcode and search factories who have a postcode like 9101 for example
My model function:
function get_search($match, $match2) { $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(); }
My controller function:
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'); $match2 = $this->input->cookie('postcode'); $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(); }
Hope someone knows what i mean.
解决方案I fixed my problem like this:
i deleted my old model and instead i made it like this:
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(); }
this way it searches for two things. the postcode who is located in the factories table and the postcode cookie who is set.
My controller:
function search() { $this->breadcrumbs->page = array('link'=> base_url().'home/search' ,'title' => 'Bedrijven Zoeken' ); $data['breadcrumbs'] = $this->breadcrumbs->get(); $this->load->view('views/header'); $this->load->view('views/search', $data); $this->load->view('views/footer'); } 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(); }
My views:
Search:
<div style="clear: both; margin-top: 10px;"></div> <div class="path"><?php echo $breadcrumbs ?></div> <div id="bigcontent"> <h1>Bedrijven zoeken</h1> <hr> <br/> <br /> <p>Voer een zoekterm en postcode in om bedrijven te zoeken.</p> <br/> <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> <br /><br /> <form method="link" action="<?= base_url('bedrijven/all')?>"> <input type="submit" value="Alle bedrijven"> </form> </div>
Searchresults:
<div style="clear: both; margin-top: 10px;"></div> <div class="path"><?php echo $breadcrumbs ?></div> <div id="bigcontent"> <h1>Bedrijven gevonden: <?= count($query); ?></h1> <?= br(1); ?> <h2>Bedrijf:</h2> <?= br(1); ?> <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> </div>
这篇关于防止覆盖控制器函数中的查询 - codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!