DragonWar% 2014-04-22 08:57 采纳率: 0%
浏览 54

多选搜索过滤器

I have 4 dropdowns that are used as search filters as shown on the picture: search filters

When the page is first loaded no filter is applied and the result is shown like this: result

So what i wanna achieve is that when the user select let's say a typology ex: apartament, the result is refreshed and automaticly shown , if the user select a location , it shows all data that are typolgy=appartament and location='xyz' and so one for the 4 filters.

These are the filters

<select name='typology_categories' id="categories" onchange="filter(this.value)">
    <option value=''>All</option>
    <option value='1'> house</option>
    <option value='2'> appartament</option>
    <option value='3'> trade center</option>
    <option value='3'> villa</option>                        
  </select>


<select name='location' id="location">
    <option value=''>All</option>
    <option value='1'> Italy</option>
    <option value='2'> Germany</option>
    <option value='3'> England</option>
    <option value='3'> USA</option>                        
  </select>

<select name='price' id="price">
    <option value="">All</option>
    <option value="1000">0 - 1,000</option>
    <option value="5000">1,000 - 5,000</option>
    <option value="50000">5,000 - 50,000</option>
    <option value="100000">50,000 - 100,000</option>
    <option value="500000">100,000 - 500,000</option>
    <option value="1000000">500,000 - 1,000,000</option>
    <option value="1000001">more then 1,000,000</option>
</select>

<select name='condition' id="condition" >
    <option value=''>All</option>
    <option value='1'> new</option>
    <option value='2'> used</option>
    <option value='3'> reconstructed</option>                      
  </select>

Here is the code that is executed when the page is loaded when no filter is applied yet:

<!-- HERE IS THE SEARCH DYNAMIC LIST on load of the page-->
                <?php 
                    $typologies_sql = "SELECT  * FROM typologies";
                    $typologies = mysql_query($typologies_sql) or die (mysql_error());
                    $numrowsTypologies = mysql_num_rows($typologies);
                    if($numrowsTypologies == 0){
                        $result = "<ul id=\"thumbs\">";
                        $result .= "No Data Found in Database";
                        $result .= "<ul id=\"thumbs\">";

                    } else {
                         $result = "<ul id=\"thumbs\">";
                            while($rowTypologies= mysql_fetch_assoc($typologies)){

                                $id                    = $rowTypologies['id'];
                                $item_id               = $rowTypologies['item_id'];
                                $title                 = htmlentities($rowTypologies['title'], ENT_COMPAT, "UTF-8");
                                $description           = htmlentities($rowTypologies['description'], ENT_COMPAT, "UTF-8");
                                $thumbnail             = htmlentities($rowTypologies['thumbnail'], ENT_COMPAT, "UTF-8");
                                $price                 = htmlentities($rowTypologies['price'], ENT_COMPAT, "UTF-8");
                                $typology_category_id  = htmlentities($rowTypologies['typology_category_id'], ENT_COMPAT, "UTF-8");
                                $typology_condition_id = htmlentities($rowTypologies['typology_condition_id'], ENT_COMPAT, "UTF-8");

                                $first = base64_encode($item_id);
                                $typologyThumbnails = "admin/app/webroot/img/uploads/typology/thumbnails/" . $thumbnail;

                                            $result .=  "<li class=\"item-thumbs span4 \">"; /* video - is the izotope data which should be passed dynamicly.*/
                                            $result .=        "<a class=\"hover-wrap fancybox-media\" data-fancybox-group=\"video\" title=\"{$description}\" href=\"new.php?id=$first\">";
                                            $result .=          "<span class=\"overlay-img\"></span>";
                                            $result .=          "<span class=\"overlay-img-thumb font-icon-search\"></span>";
                                            $result .=        "</a>";
                                            $result .=        "<img src=\"$typologyThumbnails\" alt=\"{$description}\">";
                                            $result .=  "</li>";

                            }
                        $result .= "<ul id=\"thumbs\">";

                    }
                ?>

here is after the first filter is applied:

<script src="//code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript" >
    function filter(typology_category_id){
        $.ajax({
        type: "POST",
        url: "search.php",
        data: { id: typology_category_id},
            success:function(data){
                $("#projects").html(data);
            }
        });
    }

</script> 

And the search.php file is this:

<?php  
require_once('functions/functions.php');
require_once('functions/connection.php'); 
?>
<?php 
  if (isset($_POST['id'])) {
    $id_update = trim(mysql_prep($_POST['id']));
  /* Query for the typology*/
  $queryTypologies = "SELECT * ";
  $queryTypologies .= "FROM typologies";
  if (isset($id_update) && !empty($id_update) && $id_update!='') {
   $queryTypologies .= " WHERE typology_category_id = (SELECT id FROM typology_categories WHERE id ='".$id_update."' LIMIT 1)";
  }  
  $typologies = mysql_query($queryTypologies) or die (mysql_error());
                         $result = "<ul id=\"thumbs\">";
                            while($rowTypologies= mysql_fetch_assoc($typologies)){
                                $id                    = $rowTypologies['id'];
                                $item_id               = $rowTypologies['item_id'];
                                $title                 = htmlentities($rowTypologies['title'], ENT_COMPAT, "UTF-8");
                                $description           = htmlentities($rowTypologies['description'], ENT_COMPAT, "UTF-8");
                                $thumbnail             = htmlentities($rowTypologies['thumbnail'], ENT_COMPAT, "UTF-8");
                                $price                 = htmlentities($rowTypologies['price'], ENT_COMPAT, "UTF-8");
                                $typology_category_id  = htmlentities($rowTypologies['typology_category_id'], ENT_COMPAT, "UTF-8");
                                $typology_condition_id = htmlentities($rowTypologies['typology_condition_id'], ENT_COMPAT, "UTF-8");                  
                                $first = base64_encode($item_id);
                                            $result .=  "<li class=\"item-thumbs span4 \">"; 
                                            $result .=        "<a class=\"hover-wrap fancybox-media\" data-fancybox-group=\"video\" title=\"{$description}\" href=\"new.php?id=$first\">";
                                            $result .=          "<span class=\"overlay-img\"></span>";
                                            $result .=          "<span class=\"overlay-img-thumb font-icon-search\"></span>";
                                            $result .=        "</a>";
                                            $result .=        "<img src=\"$thumbnail\" alt=\"{$description}\">";
                                            $result .=  "</li>";

                            }
                        $result .= "</ul>";
                   echo $result;
  }
    mysql_close();
 ?>

So what i wanna achieve is that on change of the drop down select filters, the result search is changed dynamicly.

Any help would be very appruciated. Thanx in advance.

  • 写回答

1条回答 默认 最新

  • weixin_33730836 2014-04-22 09:53
    关注
    //Just add a form tag in your html code..  
    <form name="search_form" id="search_form">  
    
          <select name='typology_categories' id="categories" class="select_filter">
                <option value=''>All</option>
                <option value='1'> house</option>
                <option value='2'> appartament</option>
                <option value='3'> trade center</option>
                <option value='3'> villa</option>                        
              </select>
    
    
            <select name='location' id="location" class="select_filter">
                <option value=''>All</option>
                <option value='1'> Italy</option>
                <option value='2'> Germany</option>
                <option value='3'> England</option>
                <option value='3'> USA</option>                        
              </select>
    
            <select name='price' id="price" class="select_filter">
                <option value="">All</option>
                <option value="1000">0 - 1,000</option>
                <option value="5000">1,000 - 5,000</option>
                <option value="50000">5,000 - 50,000</option>
                <option value="100000">50,000 - 100,000</option>
                <option value="500000">100,000 - 500,000</option>
                <option value="1000000">500,000 - 1,000,000</option>
                <option value="1000001">more then 1,000,000</option>
            </select>
    
            <select name='condition' id="condition" class="select_filter" >
                <option value=''>All</option>
                <option value='1'> new</option>
                <option value='2'> used</option>
                <option value='3'> reconstructed</option>                      
              </select>
        </form>
    
    
    // You Javascript code
      $('.select_filter').on('change',function(){
          $.ajax({
               type: "POST",
               url: "search.php",
               data: $('#search_form').serialize(), // You will get all the select data..
                success:function(data){
                    $("#projects").html(data);
                }
            });
      });
    
    
    // Just print the $_POST in your php i.e.echo "<pre>";print_r($_POST);echo "</pre>"; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀