当前位置:网站首页>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
边栏推荐
- 机房建设资料
- Non boost ASIO notes: UDP UART socketcan multicast UDS
- Add of cmake_ dependencies
- Code reading methods and best practices
- Install SSL Certificate in Litespeed web server
- Topological sorting & critical path
- hdu-7141 Ball (bitset)
- Hospital generic cabling
- The third week of summer vacation
- How to synchronize MySQL database when easycvr platform is upgraded to the latest version v2.5.0?
猜你喜欢

Excel simple macro

代码阅读方法与最佳实践

MGRE GRE OSPF process in hcip

Phantom core is about to close? Is there a future for digital collections?

How to solve the problem that the universal vision NVR device is connected to the easycvr platform and cannot be online after offline?

医院无线网络系统设计
![[C language operation of linked list (initialization, establishment, length calculation, addition, deletion, and output of linked list)]](/img/9b/e5cda39c04d0cc2f69e43c97ee997d.png)
[C language operation of linked list (initialization, establishment, length calculation, addition, deletion, and output of linked list)]

Study and use of burpsuite plug-in

Ora-12899 error caused by nchar character

SCM learning notes 9 -- common communication methods (based on Baiwen STM32F103 series tutorials)
随机推荐
20220723 记录一次SAP Oracle 监听服务莫名停掉的问题
机房建设资料
Research on retinal vascular segmentation based on GAN using few samples
Hcip experiment
Matplotlib save image to file
Hcip first day notes
Network type
暑假第三周
[hiflow] regularly send Tencent cloud SMS sending group
OSPF (sixth day notes)
Local empowerment learning
Arm architecture and programming 7 -- exceptions and interrupts (based on Baiwen arm architecture and programming tutorial video)
Troisième semaine d'été
"Guanghetong AI intelligent module sca825-w" with full AI performance accelerates the era of e-commerce live broadcast 2.0
Study and use of burpsuite plug-in
Number of combinations....
How the next dbcontext of efcore advanced SaaS system supports multi database migration
Exchange 2010通配符SSL证书安装文档
Excel simple macro
OSPF (fifth day notes)