2017-01-31 9 views
-3

チェックボックスをオンにしてチェックを入れたいのですが、フィルターIDを配列にプッシュしていて、チェックする必要のあるフィルターIDがあれば、これはすべて$ _GET ['filter']ですべてのフィルターを取得していますが、while以下はin_arrayは常にfalseを返しますか?

<?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> 

、以下

は、HTMLやPHPのコードで$フィルタアレイは、in_arrayは常にfalseを返す意味で、これは私を助けてくださいに誰か

を比較していますことは、私のjQueryのコードです:

<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

私は'(ISSET($のselected_filter)&& in_array($フィルタリングかどうかを確認したい[' filter_id ']、$のselected_filter)) を{?> <入力名= "フィルタ[]" タイプ= "チェックボックス"value =" <?php echo $ filter ['filter_id'];?> "checked><?php echo $ filter ['name']?> <?php} else {?> <?php echo $ filter ['name']?> ' – Mohan

答えて

0

あなたがされていますaを定義する多次元配列[]をやって:

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

in_array()

は、それが動作しませんので、配列でトップレベルに探しています。ちょうど:

$selected_filter = explode(",",$_GET['filter']); 
関連する問題