原始的代码是:
改成:
- 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;
- }
代码中红字部分即为新增代码
- 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'";
- }
- }elseif($fields[$k]['boxtype']=='checkbox' || $fields[$k]['boxtype']=='multiple') {
- $r = ','.trim($r,',').',';
- $sql .=" AND `$k` LIKE '%$r%'";
- } else {
- $sql .=" AND `$k` = '$r'";
- }
- }
- }
- return $sql;
- }