2017-01-31 10 views
-3

체크 박스를 체크하고 싶을 때, 필터 ID를 배열에 넣고 확인해야하는 필터 ID를 확인해야합니다. 이렇게하려면 $ _GET [ 'filter']에있는 모든 필터를 가져오고 있지만 while $ 필터 배열이 비교 건가요 항상와 in_array 의미 false를 돌려주는 사람이 밖으로 저를 도와주세요in_array는 항상 false를 반환합니까?

다음

입니다 HTML과 PHP 코드 내 jQuery 코드입니다 아래

<?php echo $header; 
if(isset($_GET['filter'])) 
{ 
    $selected_filter[] = explode(",",$_GET['filter']); 
    print_r($selected_filter); 
    // $flag = 1; 
} 
?> 




    <div class="wrapper"> 
    <?php echo $column_left; ?> 
    <div class="filterDiv"> 
     <h3>Filters by :</h3> 
     <!-- <div class="flList"> 
     <p>price</p> 
     <div class="flDrop price_Module"><div class="flDropDiv">price div</div></div>   
     </div> --> 
     <!-- <div class="list-group-item flList filter_options"> 
     <div class="flDrop price_Module"><div class="flDropDiv">price div</div></div>   
     <span id="amtmin"></span> - <span id="amtmax"></span> 
     <input type="hidden" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> 
     <div id="slider-range"></div> 
     </div> --> 

     <div class="flList"> 
     <p>Categories</p> 
     <div class="flDrop"> 
      <div class="flDropDiv category_fl"> 
       <?php foreach ($categories as $category) { 
       $category_name = explode("(",$category['name']) 
       ?> 
       <div class="flItems"><a href="<?php echo $category['href'] ?>"> <?php echo $category_name[0]; ?> </a> </div> 
       <?php }?> 
      </div> 
     </div>  
     </div> 

      <?php //echo "<pre>"; print_r($filter_groups); die; ?> 
     <?php foreach ($filter_groups as $filter_group) { ?> 
      <div class="flList"> 
      <p><?php echo $filter_group['name']; ?></p> 
       <div class="flDrop"> 
       <div class="flDropDiv"> 
        <?php 
        // $filter_string = ""; 
        foreach ($filter_group['filter'] as $filter) { 
         // $filter_string = implode(',',$filter['']); 
         // print_r($filter_string); 
         if(isset($selected_filter) && in_array($filter['filter_id'],$selected_filter)) 
         { ?> 
         <input name="filter[]" type="checkbox" value="<?php echo $filter['filter_id']; ?>" checked> <?php echo $filter['name'] ?> 
         <?php } else {?> 
          <input name="filter[]" type="checkbox" value="<?php echo $filter['filter_id']; ?>"> <?php echo $filter['name'] ?> 
         <?php }?> 
        <?php }?> 
       </div> 
      </div>  
      </div> 
     <?php }?> 
     <div class="flList"> 
     <?php 
     $amount_min = $min_product_price;$amount_max = $max_product_price; 
     if(isset($_GET['amtmin']) && $_GET['amtmin']!=""){ 
      $amount_min = $_GET['amtmin']; 
     } 
     if(isset($_GET['amtmax']) && $_GET['amtmax']!=""){ 
      $amount_max = $_GET['amtmax']; 
     } 
     ?> 
     <p>Price</p> 
     <div class="flDrop price_Module"> 
      <div class="flDropDiv"> 
       <!-- <a class="list-group-item fltrHdng">Price</a> -->  
       <div class="price_slide"> 
       <!-- <label for="amount">Price range</label> -->     
       <input type="hidden" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> 
       <div id="slider-range"></div> 
       <div class="cf mb10"></div> 
       <span class="pull-left" id="amtmin"></span> <span class="pull-right" id="amtmax"></span>     
       </div> 
      </div> 
     </div> 
     </div> 
     <div class="cf"></div> 
     <?php 
      if(isset($min_p) && ($max_p)){ 
      ?> 
      <div class="filterSelectPrice filterSelect afr"> 
      <div id="fSprice" class="fSbtn">Rs.<?php echo $min_p; ?> - Rs.<?php echo $max_p; ?> <span class="clear fSp"></span></div> 
      </div> 
     <?php } ?> 
     <div class="filterSelect" id="auto_filter_values"></div>  
    </div> 
    </div> 

: 당신은

<script type="text/javascript"> 

$('input[name^=\'filter\']').on('change', function() { 
     filter = []; 
     $('input[name^=\'filter\']:checked').each(function(element) { 
     filter.push(this.value); 
     $(filter).prop('checked',true); 
     }); 
     // console.log(filter);return false; 
     window.history.pushState("","",'<?php echo $action; ?>&filter=' + filter.join(',')); 
     //return false; 
     $.ajax({ 
     url: '<?php echo $action; ?>&filter=' + filter, 
     type: 'post', 
     cache: false, 
     contentType: false, 
     processData: false, 
     beforeSend: function() { 
     $('#content').block({message:'<img src="<?php echo HTTP_SERVER; ?>image/ajax-loader.gif">'}); 
     //$("#content").fadeOut("slow"); 
     }, 
     complete: function() {  

     // $(this).remove(); 
     //$("#content").fadeIn("slow"); 
     $('#content').unblock(); 
     },  
     success: function(data) { 
     $("body").empty().append(data); 
     },  
     error: function(xhr, ajaxOptions, thrownError) { 
     alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 
     } 
    }); 
    }); 
</script> 
+0

글쎄, 우리는 어떻게'$ filter [ 'filter_id']'또는'$ selected_filter'를 표시하지 않습니까? – AbraCadaver

+0

selected_filter'어레이 ( [0] => 배열 ( [0] => 81 [1] => 86 [2] => 151 ) )' $ 필터 [ "filter_id '] '81' – Mohan

+0

{({filter_id'}, $ selected_filter) $ {filter_id '})를 확인하고 싶습니다. {?> ' – Mohan

답변

0

있습니다 ~을 정의하는 다차원 배열 [] 일 :

$selected_filter[] = explode(",",$_GET['filter']); 

in_array()

가 작동하지 않도록 배열입니다 최상위 수준에서 찾고 있습니다. 그냥 :

$selected_filter = explode(",",$_GET['filter']); 
관련 문제