bordercolorlight=#999999 bordercolordark=#ffffff cellpadding=0
width=65% align=center>
项目
栏目1
栏目2
栏目3
栏目4
栏目5
栏目6
栏目7
栏目8
栏目9
栏目10
栏目11
栏目12
栏目13
栏目14
栏目15
查询范围
年 月 至
年
月
border=0 name=save src=sbcx_files/enter.gif
value=1>
我使用的是帝国cms
其中在\web\e\search\index.php里设置了各自的搜索模版,与栏目id对应,$s_tempid=(int)$_post['classid'];
选择栏目1是可以按照正常的年月份搜索的,已经实现;
选择栏目2是只能在同一年同一月查询,否则出现错误,
选择栏目3与栏目2相同,只能在同一年同一月份进行查询,否则显示错误;
选择栏目4是只能选择同一年1月同一年3月份,(4月份6月份),按季度查询,否则产生错误。
选择栏目5是可以选择01-04,所查询出来的是1条01-03月份的记录,如果查询02-04,会产生错误,如果查询01-07,所查询出来的是2条01-03,04-06月份记录,就是包含季度查询。
应该在\web\e\search\index.php里如何修改?
回复讨论(解决方案) '.$keyboard.';
}
elseif($hh=='eq')//等于
{
$where=$f.='.$keyboard.';
}
elseif($hh=='le')//小于等于
{
$where=$f. }
elseif($hh=='ge')//大于等于
{
$where=$f.>='.$keyboard.';
}
elseif($hh=='ne')//不等于
{
$where=$f.'.$keyboard.';
}
elseif($hh=='in')//包含
{
$kr=explode(' ',$keyboard);
$kcount=count($kr);
$kbs='';
$dh='';
for($i=0;$i {
if(empty($kr[$i]))
{
continue;
}
if($kbs)
{
$dh=',';
}
$kbs.=$dh.'.$kr[$i].';
}
if($kbs)
{
$where=$f. in (.$kbs.);
}
else
{
return '';
}
}
elseif($hh=='bt')//范围
{
$keyboard=ltrim($keyboard);
if(!strstr($keyboard,' '))
{
return '';
}
$kr=explode(' ',$keyboard);
if(!trim($kr[0])||!trim($kr[1]))
{
return '';
}
$where=$f. between '.$kr[0].' and '.$kr[1].';
}
else//相似
{
$where=$f. like '%.str_replace( ,%,$keyboard).%';
}
}
else
{
$where=$f. like '%.str_replace( ,%,$keyboard).%';
}
return $where;
}
//变量
if($_get['searchget']==1)
{
$_post=$_get;
}
$ip=egetip();
$searchtime=time();
$getvar=$_post['getvar'];
if(empty($getvar))
{
$getfrom=history.go(-1);
$dogetvar='';
}
else
{
$getfrom=../../search/;
$dogetvar=&getvar=1;
}
//搜索用户组
if($public_r['searchgroupid'])
{
$psearchgroupid=$public_r['searchgroupid'];
@include(../data/dbcache/memberlevel.php);
$searchgroupid=(int)getcvar('mlgroupid');
if($level_r[$searchgroupid][level] {
printerror(notleveltosearch,$getfrom,1);
}
}
//搜索间隔
$lastsearchtime=getcvar('lastsearchtime');
if($lastsearchtime)
{
if($searchtime-$lastsearchtime {
printerror(searchouttime,$getfrom,1);
}
}
//搜索字段
$searchclass=$_post['show'];
if(empty($searchclass)||strstr($searchclass, ))
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
//时间范围
$add='';
$addtime='';
$sssqqyear=$_post['sssq_q_year'];
$sssqqmonth=$_post['sssq_q_month'];
$sssqzyear=$_post['sssq_z_year'];
$sssqzmonth=$_post['sssq_z_month'];
$starttime=$sssqqyear.-.$sssqqmonth.-01;
if(empty($starttime))
{
$starttime=0000-00-00;
}
$endtime=$sssqzyear.-.$sssqzmonth.-01;
if(empty($endtime))
{
$endtime=0000-00-00;
}
if($endtime!=0000-00-00)
{
$addtime= and (newstime between '.to_time($starttime. 00:00:00).' and '.to_time($endtime. 23:59:59).');
}
//jiage
$addprice='';
$startprice=(int)$_post['startprice'];
$endprice=(int)$_post['endprice'];
if($endprice)
{
$addprice= and (price between .$startprice. and .$endprice.);
}
//搜索栏目及表
$classid=reppostvar($_post['classid']);
$s_tbname=reppostvar($_post['tbname']);
$s_tempid=(int)$_post['classid'];
$trueclassid=0;
if($classid)//按栏目
{
if(strstr($classid,,))//多栏目
{
$son_r=sys_returnmoreclass($classid,1);
$trueclassid=$son_r[0];
$add.=' and ('.$son_r[1].')';
}
else
{
$trueclassid=intval($classid);
$add.=$class_r[$trueclassid][islast]? and classid='$trueclassid': and .returnclass($class_r[$trueclassid][sonclass]);
}
$tbname=$class_r[$trueclassid][tbname];
$modid=$class_r[$trueclassid][modid];
}
elseif($s_tbname)//按数据表
{
$tbnamenum=$empire->gettotal(select count(*) as total from {$dbtbpre}enewstable where tbname='$s_tbname' limit 1);
if(!$tbnamenum)
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
$tbname=$s_tbname;
//模型id
$thestemp_r=$empire->fetch1(select modid from .gettemptb(enewssearchtemp). where tempid='$s_tempid');
if(empty($thestemp_r['modid']))
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
$modid=$thestemp_r['modid'];
}
else
{
$tbname=$public_r['tbname'];
$modid=0;
}
//表不存在
if(empty($tbname))
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
//专题
$ztid=reppostvar($_post['ztid']);
$trueztid=0;
if($ztid)
{
if(strstr($ztid,,))//多专题
{
$son_r=sys_returnmorezt($ztid);
$trueztid=$son_r[0];
$add.=' and ('.$son_r[1].')';
}
else
{
$trueztid=intval($ztid);
$add.= and ztid like '%|.$trueztid.|%';
}
}
//会员
$member=$_post['member'];
if($member==1)
{
$add.=' and ismember=1';
}
elseif($member==2)
{
$add.=' and ismember=0';
}
//模型
$tempr=array();
if(empty($class_r[$trueclassid][searchtempid]))
{
if(empty($modid))
{
$tempr=$empire->fetch1(select modid from .gettemptb(enewssearchtemp). where isdefault=1 limit 1);
}
else
{
$tempr[modid]=$modid;
}
}
else
{
$tempr[modid]=$modid;
}
//关键字
$keyboard=$_post['keyboard'];
$keyboardone=0;
if(is_array($keyboard))
{}
elseif(strstr($keyboard,','))
{
$keyboard=explode(',',$keyboard);
}
else
{
$keyboard=trim($keyboard);
$len=strlen($keyboard);
if($len$public_r[max_keyboard])
{
printerror(minkeyboard,$getfrom,1);
}
$keyboardone=1;
}
//符号
$hh=$_post['hh'];
$hhone=0;
if(is_array($hh))
{}
elseif(strstr($hh,','))
{
$hh=explode(',',$hh);
}
else
{
$hhone=1;
}
//字段
if(!is_array($searchclass))
{
$searchclass=explode(',',$searchclass);
}
$andor=$_post['andor'];
$andor=$andor=='and'?'and':'or';
$mr=$empire->fetch1(select searchvar,tbname from {$dbtbpre}enewsmod where mid='$tempr[modid]');
if(!strstr($mr[searchvar],,price,))//是否包含价格
{
$addprice=;
$startprice=0;
$endprice=0;
}
//搜索特殊字段
$mr[searchvar].='id,keyboard,userid,username,';
$where='';
$newsearchclass='';
$count=count($searchclass);
for($i=0;$i {
if(empty($searchclass[$i]))
{
continue;
}
$searchclass[$i]=str_replace(',','',$searchclass[$i]);
if(!strstr($mr[searchvar],,.$searchclass[$i].,))
{
continue;
}
$searchclass[$i]=reppostvar($searchclass[$i]);
$dh=empty($newsearchclass)?'':',';
$newsearchclass.=$dh.$searchclass[$i];
$dohh=$hhone==1?$hh:$hh[$i];
$dokeyboard=$keyboardone==1?$keyboard:$keyboard[$i];
$onewhere=searchdokeyboard($searchclass[$i],$dohh,$dokeyboard);
if($onewhere)
{
$or=empty($where)?'':' '.$andor.' ';
$where.=$or.'('.$onewhere.')';
}
}
//参数错
if(empty($newsearchclass))
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
if($where)
{
$add.=' and ('.$where.')';
}
$allwhere=$add.$addtime.$addprice;
$keyboard=$keyboardone==1?searchdokeyboardvar($keyboard):'';
$andsql=addslashes($allwhere);
if(strlen($newsearchclass)>250||strlen($classid)>200||strlen($andsql)>3000||strlen($keyboard)>100||strlen($ztid)>200)
{
header(location:result/?searchid=0.$dogetvar);
exit();
}
//验证码
$checkpass=md5($allwhere.$tbname);
$query=select count(*) as total from {$dbtbpre}ecms_.$tbname. where checked=1.$allwhere;
$search_r=$empire->fetch1(select searchid from {$dbtbpre}enewssearch where checkpass='$checkpass' limit 1);
$searchid=$search_r[searchid];
//排序
$orderby=reppostvar($_post['orderby']);
$myorder=(int)$_post['myorder'];
if($orderby)
{
$orderr=returndoorderf($tempr[modid],$orderby,$myorder);
$orderby=$orderr['returnf'];
}
else
{
$orderby='newstime';
}
//是否有历史记录
if($searchid)
{
$search_num=$empire->gettotal($query);
$sql=$empire->query(update {$dbtbpre}enewssearch set searchtime='$searchtime',result_num='$search_num',onclick=onclick+1,orderby='$orderby',myorder='$myorder',tempid='$s_tempid' where searchid='$searchid');
if(empty($search_num))
{
$searchid=0;
}
}
else
{
$search_num=$empire->gettotal($query);
if(empty($search_num))
{
$searchid=0;
}
else
{
$iskey=$keyboardone==1?0:1;
$sql=$empire->query(insert into {$dbtbpre}enewssearch(searchtime,keyboard,searchclass,result_num,searchip,classid,onclick,orderby,myorder,checkpass,tbname,tempid,iskey,andsql,trueclassid) values('$searchtime','$keyboard','$newsearchclass','$search_num','$ip','$classid',1,'$orderby','$myorder','$checkpass','$tbname','$s_tempid','$iskey','$andsql','$trueclassid'));
$searchid=$empire->lastid();
}
}
//设置最后搜索时间
$set1=esetcookie(lastsearchtime,$searchtime,$searchtime+3600*24);
db_close();
$empire=null;
header(location:result/?searchid=$searchid.$dogetvar);
?>
