我有一个搜索查询,用于在输入(邮政编码)周围 x 公里的半径范围内搜索工厂。它工作正常,但问题是我无法搜索输入(邮政编码),所以当我输入 9101 时,它不会搜索该邮政编码,只搜索它周围的邮政编码。
我的查询如下所示:
$string = implode($_SESSION['postcodes'], '|');
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 REGEXP '$string')
GROUP BY `Categorie`, `bedrijfcategorieen`.`idbedrijven`";
$query = $this->db->query($query);
echo '<pre>';
echo '</pre>';
$result = $query->result_array();
return $result;
这$_SESSION['postcodes']
是我的邮政编码周围一定半径内所有邮政编码的会话。我有另一个会话称为searched_post_code
此会话,用于输入,例如“9101”。
如何使用填写的邮政编码和填写的搜索词搜索工厂?
我的搜索表单如下所示:
请注意大的“搜索”输入以及半径和邮政编码输入。
我还想将任何搜索词与我搜索的邮政编码相匹配。
表格代码:
<form name="input" method="post" action="searchresults" class="pro6pp_range">
<input type="search" onchange="validate()" placeholder="Zoeken..." name="search" size="70">
<select class="range">
<option value="5" selected="selected">5 km</option>
<option value="10">10 km</option>
<option value="15">15 km</option>
<option value="20">20 km</option>
<option value="25">25 km</option>
</select>
<input type="search" name="searchpc" class="postcode" value="<?= $this->input->cookie('postcode'); ?>" placeholder="Postcode (1234)" maxlength="4">
<input type="submit" value="Zoeken">
我希望它有点清楚:
你可以看到它在这里工作
sql输出示例:
SELECT * FROM ( )
bedrijfcategorieen
加入。= 。加入 。_ = 。WHERE ( LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%' OR LIKE '%design%') AND (邮政编码 REGEXP '9100|9101|9121|9103|9148|9156|9146|9122|9155|9154|9147|9125|9144|9106|9138|9113|9104|9153|' ) 分组依据, .bedrijven
bedrijfcategorieen
idbedrijven
bedrijven
idbedrijven
categorieen
bedrijfcategorieen
idcategorieen
categorieen
idcategorieen
Bedrijfsnaam
Plaats
Telefoonnummer
Website
Profiel
Adres
Categorie
Categorie
bedrijfcategorieen
idbedrijven