-2

我一直试图让这个网页工作一段时间,但一直遇到问题。在这个网页中,我有一系列选择框(有些是独立的,有些是依赖于另一个的)进行选择,然后应用过滤器进行查询。它仍处于测试模式,并且对于单个选择工作正常。但我仍然没有设法使其适用于同一选择框中的多项选择。例如; 当我在区域框中选择欧洲和北美并应用过滤器时,它没有给出任何结果,而我希望它能给我提供位于欧洲或北美的公司的结果。你可以在这里找到测试网页:http: //gorevler.awardspace.biz/realdeal04.html

我一直在尝试在 .PHP 文件中使用“内爆”和 IN 运算符,但不知道我在哪里做错了。如果你能告诉我正确的做法,我将不胜感激。您可以在下面找到代码:

PHP

<?php

error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR |     MYSQLI_REPORT_STRICT);

$DB_HOST = "*****"; $DB_USER = "*****"; $DB_PASS = "*****"; $DB_NAME =   "*******";

$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if($con->connect_errno > 0) {       die('Connection failed [' . $con->connect_error . ']'); }


$bolge= "'" . implode("', '", $_POST['filtre_region']) . "'" ;
$bolge1= mysqli_real_escape_string($con,$bolge);

$ulke= "'" . implode("', '", $_POST['filtre_country']) . "'";
$ulke1= mysqli_real_escape_string($con,$ulke);

$sektor= "'" . implode("', '", $_POST['filtre_sector']) . "'";
$sektor1= mysqli_real_escape_string($con,$sektor);

$altsektor= "'" . implode("', '", $_POST['filtre_subsector']) . "'";
$altsektor1= mysqli_real_escape_string($con,$altsektor);;

$urun= "'" . implode("', '", $_POST['filtre_product']) . "'"; 
$urun1= mysqli_real_escape_string($con,$urun);

$sql = mysqli_query("SELECT * FROM gorevler WHERE region IN ('$bolge1') AND country IN ('$ulke1')     AND sector IN ('$sektor1') AND sub_sector IN ('$altsektor1') AND product IN ('$urun1')");

echo "<table border='0'>
<tr>
<th>No</th>
<th>Company</th>
<th>Region</th>
<th>Country</th>
<th>Sector</th>
<th>Sub Sector</th>
<th>Product</th>
<th>Website</th>
</tr>";

while ($row = mysqli_fetch_array($sql)){


echo "<td>" .  ''.$row['no'] . "</td>";
echo "<td>" . ''.$row['company'] . "</td>";
echo "<td>" . ''.$row['region'] . "</td>";
echo "<td>" . ''.$row['country'] . "</td>";
echo "<td>" . ''.$row['sector'] . "</td>";
echo "<td>" . ''.$row['sub_sector'] . "</td>";
echo "<td>" . ''.$row['product'] . "</td>";
echo "<td>" . ''.$row['website'] . "</td>";
echo "</tr>";
}
echo "</table>";

?>

HTML

<form id="filtersForm" action="search_company.php" method="post" target="_blank">

<fieldset id="filtersPane">

<div class="part03_line01" id="part03_line01">

  <div class="filter_bolge" id="filtre_bolge"><p>Region:</p>
   <select id="filter_region" name="filtre_region[]" class="select_bolge" title="Select a region" multiple="multiple" size="5">
     </select>    
      </div>

  <div class="filter_ulke" id="filtre_ulke"><p>Country:</p>
   <select id="filter_country" name="filtre_country[]" class="select_ulke" title="Select a   country" multiple="multiple" size="5">
     </select>    

  </div>   

  <div class="filter_sektor" id="filtre_sektor"><p>Sector:</p>
   <select id="filter_sector" name="filtre_sector[]" class="select_sektor" title="Select a  sector" multiple="multiple" size="5">
     </select>    

</div> 

<div class="filter_altsektor" id="filtre_altsektor"><p>Sub Sector:</p>
  <select id="filter_subsector" name="filtre_subsector[]" disabled="disabled"  class="select_altsektor" title="Select a sub-sector" multiple="multiple" size="5">
<option value="" data-filter-type="" selected="selected">
-- Make a Choice --</option>

</select>      
      </div>
<div class="filter_urun" id="filtre_urun"><p>Product:</p>
<select id="filter_product" name="filtre_product[]" disabled="disabled" class="select_urun"  title="Select a product" multiple="multiple" size="5">
<option value="" data-filter-type="" selected="selected">
-- Make a Choice --</option>

</select>   

</div>
</div>   

<div class="part03_line03" id="part03_line03">
  <div class="aramadugmesi" id="aramadugmesi"> <button type="submit" id="applyFilterButton">Apply Filters</button>
</div>         
</div>
</fieldset>  
</form> 

JAVASCRIPT

<script>

$(document).ready(function() { 

$('#filter_region')
.load('/textdata/region.txt');

$('#filter_country')
.load('/textdata/country.txt');


$('#filter_sector')
.load('/textdata/sector.txt');

$('#filter_sector').change(function() {
$('#filter_subsector').load("textdata/subsector/" + $(this).val() + ".txt",
function(){
$(this).attr('disabled',false);
}
);
});

$('#filter_subsector').change(function(){
$('#filter_product').load(
"textdata/subsector/product/" + $(this).val() + ".txt",
function(){
$(this).attr('disabled',false);
}
);
});
});
</script>

这个 PHP 编码对我不起作用。当我单击应用过滤器时,它没有给出任何结果。例如,当我在选择框中选择欧洲和北美并单击应用时,我希望从数据库中获取所有位于欧洲或北美的公司并列出。但它没有结果。我猜这是php编码的问题,但我不知道出了什么问题

4

1 回答 1

1

您需要在括号内加上单引号,如下所示:

$bolge1 = "'" . implode("', '", $_POST['filtre_region']) . "'";

mysql需要看到这样的东西:

IN ('value1','value2','value3')

你的爆炸只是产生了这个:

IN (value1, value2, value3)

上面的代码将插入开始和结束撇号,并确保每个值之间也有撇号。

于 2014-05-25T15:26:03.737 回答