search
Homephp教程PHP源码经典分类筛选

经典分类筛选

May 23, 2016 am 08:39 AM
Classification filter

2.png

url.php

<?php
header(&#39;Content-Type:text/html;charset=utf-8&#39;);
 
/**
 * 生成分类信息中的筛选菜单
 * @param $field   字段名称
 * @param $modelid  模型ID
 * @param $diyarr 数据包
 * @param $isall 是否显示全部
 */
function info_filters($field = &#39;&#39;,$diyarr = array(),$groups=array(),$isall = 1) {
  $options = $diyarr;
  $field_value = isset($_GET[$field])?intval($_GET[$field]):&#39;&#39;;
  foreach($options as $k=>$v) {
    $option[$k][&#39;name&#39;] = $v;
    $option[$k][&#39;value&#39;] = $k;
    $option[$k][&#39;url&#39;] = info_filters_url($field,array($field=>$k),$groups);
    $option[$k][&#39;menu&#39;] = $field_value == $k ? &#39;<a href="#" class="hover">&#39;.$v.&#39;</a>&#39; : &#39;<a href="&#39;.$option[$k][&#39;url&#39;].&#39;">&#39;.$v.&#39;</a>&#39;;
  }
  if ($isall) {
    $all[&#39;name&#39;] = &#39;全部&#39;;
    $all[&#39;url&#39;] = info_filters_url($field,array($field=>&#39;&#39;),$groups);
    $all[&#39;menu&#39;] = $field_value == &#39;&#39; ? &#39;<a href="#" class="hover">&#39;.$all[&#39;name&#39;].&#39;</a>&#39; : &#39;<a href="&#39;.$all[&#39;url&#39;].&#39;">&#39;.$all[&#39;name&#39;].&#39;</a>&#39;;
    array_unshift($option,$all);
  }
  return $option;
}
 
 
 
/**
 * 构造筛选URL
 */
function info_filters_url($fieldname, $array=array(),$fields=array(), $isphp = 0) {
  if(empty($array)) {
    $array = $_GET;
  } else {
    $array = array_merge($_GET,$array);
  }
  //TODO
  if(is_array($fields) && !empty($fields)) {
    ksort($fields);
    $urlpars =&#39;&#39;;
    foreach ($fields as $_v=>$_k) {
        $urlpars .= &#39;&&#39;.$_v.&#39;={$&#39;.$_v.&#39;}&#39;;
    }
  }
   $urlrule =&#39;urlurl.php?m=content&c=index&a=lists&catid=1&#39;.$urlpars;
  //根据get传值构造URL
 if (is_array($array)) foreach ($array as $_k=>$_v) {
    if($_k==&#39;page&#39;) $_v=1;
    $_findme[] = &#39;/{\$&#39;.$_k.&#39;}/&#39;;
    $_v = intval($_v);
    $_replaceme[] = $_v;
  }
  //构造排除该字段名称的正则
  $filter = &#39;&#39;;
  $_findme[] = &#39;/{\$&#39;.$filter.&#39;([a-z0-9_]+)}/&#39;; 
  $_replaceme[] = &#39;&#39;;
  $urlrule = preg_replace($_findme, $_replaceme, $urlrule);
  return $urlrule;
}
?>
<style>
a{ color:#333333;}
.hover{ color:#FF0000;}
</style>
 <div class="yk_01 fix">
             
            <div class="yy1">
               <?php 
                   $groups = array(
                                 &#39;dest&#39;=>array(1=>&#39;北京&#39;,2=>&#39;上海&#39;,3=>&#39;天津&#39;),
                                 &#39;action&#39;=>array(1=>&#39;香港&#39;,2=>&#39;澳门&#39;,3=>&#39;台湾&#39;)
                          );
                   $dest_list = info_filters(&#39;dest&#39;,$groups[&#39;dest&#39;],$groups);
                   $action_list = info_filters(&#39;action&#39;,$groups[&#39;action&#39;],$groups);
                   echo &#39;<span>出发城市:</sapn>&#39;;
                   foreach($dest_list as $val){
                   echo $val[&#39;menu&#39;].&#39;  &#39;;
                   }
                   echo &#39;<br/><span>目标城市:</sapn>&#39;;
                   foreach($action_list as $val){
                   echo $val[&#39;menu&#39;].&#39;  &#39;;
                   }
               ?>
            </div>
        </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft