当前位置:网站首页>Phpcms realizes product multi condition screening function
Phpcms realizes product multi condition screening function
2022-07-24 01:50:00 【Lai Zhongbiao】
The multi condition filtering function of the product is shown in the figure :

1. First , Add the following code to phpcms/libs/functions/extention.func.php Go inside
<?php
/**
* extention.func.php User defined function library
*
* @copyright (C) 2005-2010 PHPCMS
* @license http://www.phpcms.cn/license/
* @lastmodify 2010-10-27
*/
/**
* By designation keyid Display all linkage menus in the form
* @param $keyid Menu main id
* @param $linkageid Linkage menu id,0 Call top level
* @param $modelid Model id
* @param $fieldname Field name
*/
function show_linkage($keyid, $linkageid = 0, $modelid = '', $fieldname='zone') {
$datas = $infos = $array = array();
$keyid = intval($keyid);
$linkageid = intval($linkageid);
// Current menu id
$field_value = intval($_GET[$fieldname]);
$urlrule = structure_filters_url($fieldname,$array,1,$modelid);
if($keyid == 0) return false;
$datas = getcache($keyid,'linkage');
$infos = $datas['data'];
foreach($infos as $k=>$v){
if($v['parentid']==$field_value){
$array[$k]['name'] = $v['name'];
$array[$k]['value'] = $k;
$array[$k]['url'] = str_replace('{'.$fieldname.'}',$k,$urlrule);
$array[$k]['menu'] = $field_value == $k ? '<em>'.$v['name'].'</em>' : '<a href='.$array[$k]['url'].'>'.$v['name'].'</a>' ;
}
}
return $array;
}
/**
* Construct filter URL
*/
function structure_filters_url($fieldname,$array=array(),$type = 1,$modelid) {
if(empty($array)) {
$array = $_GET;
} else {
$array = array_merge($_GET,$array);
}
//TODO
$fields = getcache('model_field_'.$modelid,'model');
if(is_array($fields) && !empty($fields)) {
ksort($fields);
foreach ($fields as $_v=>$_k) {
if($_k['filtertype'] || $_k['rangetype']) {
if(strpos(URLRULE,'.html') === FALSE) $urlpars .= '&'.$_v.'={$'.$_v.'}';
else $urlpars .= '-{$'.$_v.'}';
}
}
}
// In the later stage, add pseudo static and other url Rule management ,apache Pseudo static support 9 Parameters
if(strpos(URLRULE,'.html') === FALSE) $urlrule =APP_PATH.'index.php?m=content&c=index&a=lists&catid={$catid}'.$urlpars.'&page={$page}' ;
else $urlrule =APP_PATH.'list-{$catid}'.$urlpars.'-{$page}.html';
// according to get Value passing structure URL
if (is_array($array)) foreach ($array as $_k=>$_v) {
if($_k=='page') $_v=1;
if($type == 1) if($_k==$fieldname) continue;
$_findme[] = '/{\$'.$_k.'}/';
$_replaceme[] = $_v;
}
//type In mode , Construct a regular that excludes the field name
if($type==1) $filter = '(?!'.$fieldname.'.)';
$_findme[] = '/{\$'.$filter.'([a-z0-9_]+)}/';
$_replaceme[] = '';
$urlrule = preg_replace($_findme, $_replaceme, $urlrule);
return $urlrule;
}
/**
* Generate the filter menu in the classification information
* @param $field Field name
* @param $modelid Model ID
*/
function filters($field,$modelid,$diyarr = array()) {
$fields = getcache('model_field_'.$modelid,'model');
$options = empty($diyarr) ? explode("\n",$fields[$field]['options']) : $diyarr;
$field_value = intval($_GET[$field]);
foreach($options as $_k) {
$v = explode("|",$_k);
$k = trim($v[1]);
$option[$k]['name'] = $v[0];
$option[$k]['value'] = $k;
$option[$k]['url'] = structure_filters_url($field,array($field=>$k),2,$modelid);
$option[$k]['menu'] = $field_value == $k ? '<em>'.$v[0].'</em>' : '<a href='.$option[$k]['url'].'>'.$v[0].'</a>' ;
}
$all['name'] = ' All ';
$all['url'] = structure_filters_url($field,array($field=>''),2,$modelid);
$all['menu'] = $field_value == '' ? '<em>'.$all['name'].'</em>' : '<a href='.$all['url'].'>'.$all['name'].'</a>';
array_unshift($option,$all);
return $option;
}
/**
* Get the linkage menu level
* @param $keyid Linkage menu classification id
* @param $linkageid menu id
* @param $leveltype Access to type parentid Get the parent id child There are sub columns when obtaining arrchildid Get the sub column array
*/
function get_linkage_level($keyid,$linkageid,$leveltype = 'parentid') {
$child_arr = $childs = array();
$leveltypes = array('parentid','child','arrchildid','arrchildinfo');
$datas = getcache($keyid,'linkage');
$infos = $datas['data'];
if (in_array($leveltype, $leveltypes)) {
if($leveltype == 'arrchildinfo') {
$child_arr = explode(',',$infos[$linkageid]['arrchildid']);
foreach ($child_arr as $r) {
$childs[] = $infos[$r];
}
return $childs;
} else {
return $infos[$linkageid][$leveltype];
}
}
}
// according to linkageid Recursion to parent
function get_parent_url($modelid,$field,$linkageid=0,$array = array()){
$modelid = intval($modelid);
if(!$modelid || empty($field)) return false;
$fields = getcache('model_field_'.$modelid,'model');
$keyid = $fields[$field]['linkageid'];
$datas = getcache($keyid,'linkage');
$infos = $datas['data'];
if(empty($linkageid)){
$linkageid = intval($_GET[$field]);
if(!$linkageid) return false;
}
$urlrule = structure_filters_url($field,array(),1,$modelid);
$urlrule = str_replace('{$'.$field.'}',$infos[$linkageid]['parentid'],$urlrule);
array_unshift($array,array('name'=> $infos[$linkageid]['name'],'url'=>$urlrule));
if($infos[$linkageid]['parentid']){
return get_parent_url($modelid,$field,$infos[$linkageid]['parentid'],$array);
}
return $array;
}
/**
* When constructing screening sql sentence
*/
function structure_filters_sql($modelid) {
$sql = $fieldname = $min = $max = '';
$fieldvalue = array();
$modelid = intval($modelid);
$model = getcache('model','commons');
$fields = getcache('model_field_'.$modelid,'model');
$fields_key = array_keys($fields);
//TODO
$sql = '`status` = \'99\'';
foreach ($_GET as $k=>$r) {
if(in_array($k,$fields_key) && intval($r)!=0 && ($fields[$k]['filtertype'] || $fields[$k]['rangetype'])) {
if($fields[$k]['formtype'] == 'linkage') {
$datas = getcache($fields[$k]['linkageid'],'linkage');
$infos = $datas['data'];
if($infos[$r]['arrchildid']) {
$sql .= ' AND `'.$k.'` in('.$infos[$r]['arrchildid'].')';
}
} elseif($fields[$k]['rangetype']) {
if(is_numeric($r)) {
$sql .=" AND `$k` = '$r'";
} else {
$fieldvalue = explode('_',$r);
$min = intval($fieldvalue[0]);
$max = $fieldvalue[1] ? intval($fieldvalue[1]) : 999999;
$sql .=" AND `$k` >= '$min' AND `$k` < '$max'";
}
} else {
$sql .=" AND `$k` = '$r'";
}
}
}
return $sql;
}
/**
* Pagination , If it is removed, there will be problems with paging
*/
function makeurlrule() {
if(strpos(URLRULE,'.html') === FALSE) {
return url_par('page={$'.'page}');
}
else {
$url = preg_replace('/-[0-9]+.html$/','-{$page}.html',get_url());
return $url;
}
}
?>2. then , Content —— Model management —— Select a model to add a new field Pictured

3. then , Add a label to the foreground column template page to call product filtering as follows :
Filter condition code :
<span> Gender :</span>
{loop filters('xingbie',$modelid) $r}
{$r[menu]}
{/loop}Filter data result code :
{php $sql = structure_filters_sql($modelid)}
{php $urlrule = makeurlrule()}
{pc:content action="lists" where="$sql" catid="$catid" num="10" order="id DESC" page="$page" urlrule="$urlrule"}
<ul class="photo-list picbig">
{loop $data $r}
<li>
<div class="img-wrap">
<a href="{$r[url]}"><img src="{thumb($r[thumb],150,112)}" width="150" height="112" alt="{$r[title]}"/></a>
</div>
<span style="color:{$r[style]}">{str_cut($r[title],28)}</span>
</li>
{/loop}
</ul>
<div id="pages" class="text-c">{$pages}</div>
{/pc}Green tea
2022.7.22
边栏推荐
- LiteSpeed Web服务器中安装SSL证书
- J. Serval and essay (tarjan finds topological order)
- The third week of summer vacation
- Cartland number---
- Local empowerment learning
- 快速排序注意点
- Detailed explanation of php7 garbage collection mechanism
- win11系统之win11亮点
- How to finally generate a file from saveastextfile in spark
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
猜你喜欢

SCM learning notes 9 -- common communication methods (based on Baiwen STM32F103 series tutorials)

Arm architecture and programming 4 -- serial port (based on Baiwen arm architecture and programming tutorial video)

Introduction and environment construction of little bear sect

Exchange 2013 SSL certificate installation document

Retinal network based on enhanced spatial attention (ESA UNET)

Notes - record the solution to the failure of @refreshscope dynamic refresh configuration
![[pumpkin Book ml] (task3) decision tree (updating)](/img/4c/fc7157518ad729400d605b811323de.png)
[pumpkin Book ml] (task3) decision tree (updating)

Install go environment under Kali

Hcip second day notes

jmeter+influxdb+grafana压测实时监控平台搭建
随机推荐
[bdsec CTF 2022] partial WP
php7 垃圾回收机制详解
Rip (notes of the second day)
代码阅读方法与最佳实践
What is restful
医院综合布线
How the next dbcontext of efcore advanced SaaS system supports multi database migration
How to use the directory classification function of the new version of easycvr (v2.5.0)?
How CAD draws arrows with arcs
Hcip day 10 notes
Database security and data integrity
Basic knowledge of mathematical vector
Structure the second operation of the actual combat battalion module
Hospital network security architecture
Digicert code signing certificate
Hcip second day notes
Install go environment under Kali
Try to run this command from the system terminal Make sure that you use the correct
Perlin noise and random terrain
Simple Gan instance code