问题发布与回答 发表于 2021-5-1 22:16:16

ASPCMS多条件查询

ASPCMS多条件查询

1. 表单样例:
                <form name="topFrm"id="topFrm" action="/search.asp"><input name="searchType" type="hidden" value="3" id="searchType" /><input name="keys" type="hidden" value="all" id="keys" /><div class="search-li"><input name="Title" type="text" class="search-input" id="Title" /><span>项目名称:</span></div><div class="search-li"><input class="search-input" name="P_Area" type="text" id="P_Area" /><span>区域:</span></div><div class="search-li"><input class="search-input" name="P_Room" type="text" id="P_Room" /><span>房型:</span></div><div class="search-li"><input class="search-input" name="P_Cost" type="text" id="P_Cost" /><span>造价:</span></div><div class="search-li"><input class="search-input" name="P_DesignStyle" type="text" id="P_DesignStyle" /><span>风格:</span></div><div class="search-btn"><ahref="javascript:topsearchSubmit();"><img src="{aspcms:sitepath}/Templates/{aspcms:defaulttemplate}/images/search_btn.gif" /></a></div></form>
<script type="text/javascript">function topsearchSubmit(){topFrm.submit();return false;}</script>
2. 修改"/inc/AspCms_MainClass.asp",修改查询语句(在源码的1484行)
'ASPCMS Start'                  dim typeStr: typeStr=""'                  dim searchType'                  searchType=filterPara(getForm("searchType","get"))'                  if isnul(searchType) then searchType="0"'                  ifnot "0"=searchTypethen typeStr=" and a.SortID in (select {PRefix}Sort.sortid from {prefix}Sort where sortType="&searchType&") "'                  sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,Contenttag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.,a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from {prefix}Content as a,{prefix}Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%'"&typeStr&orderStr'ASPCMS End
把上面修改成:
'Feva StartDim typeStr: typeStr=""Dim searchTypesearchType=filterPara(getForm("searchType","get"))If isnul(searchType) Then searchType="0"If Not "0"=searchTypeThen typeStr=" and a.SortID in (select {prefix}Sort.sortid from {prefix}Sort where sortType="&searchType&") "If Not keys="all" Thensql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.,a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from {prefix}Content as a,{prefix}Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%'"&typeStr&orderStrElseDim formInput, keyValue, tempString : tempString = ""For Each formInput In Request.QueryStringIf Not formInput = "searchType" And Not formInput = "keys" And Not formInput = "page"ThenkeyValue = filterPara(getForm(formInput, "get"))If Len(keyValue) > 0 And Len(filterPara(formInput)) > 0ThentempString = tempString & " and " & formInput & " like '%" & keyValue & "%'"End IfEnd IfNexttempString = tempString & " "sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.,a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from {prefix}Content as a,{prefix}Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&")"& tempString &typeStr&orderStrEnd If'Feva End
3. 修改"/inc/AspCms_CommonFun.asp",添加函数:
'Feva Start'多条件分页使用Function conditionSearch()Dim keys : keys =filterPara(getForm("keys", "get"))If Not keys="all" Then'            strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchtype="&searchtype&""">"&pagenumber&"</a>"conditionSearch = ""Exit FunctionElseDim formInput, keyValue, tempString : tempString = ""For Each formInput In Request.QueryStringIf Not formInput = "searchType" And Not formInput = "keys" And Not formInput = "page" ThenkeyValue = filterPara(getForm(formInput, "get"))If Len(keyValue) > 0 And Len(filterPara(formInput)) > 0 ThentempString = tempString & "&" & formInput & "=" & keyValueEnd IfEnd IfNextconditionSearch = tempStringExit Function'      strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchType="&searchtype&tempString&""">"&pagenumber&"</a>"End IfEnd Function'Feva End
3. 修改"/inc/AspCms_CommonFun.asp",分页中部函数 Function makePageNumber(Byval currentPage,Byval pageListLen,Byval totalPages,Byval linkType,Byval sortid, Byval showType) 修改:
'ASPCMSStart'                strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchtype="&searchtype&""">"&pagenumber&"</a>"'ASPCMSEnd
修改成:
'Feva Start'注意searchType大小写问题strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchType="&searchtype& conditionSearch() &""">"&pagenumber&"</a>"'Feva End
4. 修改"/inc/AspCms_CommonFun.asp",分页两侧函数 Function pageNumberLinkInfo(Byval currentPage,Byval pageListLen,Byval totalPages,Byval linkType,Byval sortid, Byval showType) 修改
'ASPCMS Start'            firstPageLink="<a href='?page=1&keys="&keys&"&searchtype="&searchtype&"'>"&str_01&"</a>" : lastPagelink="<a href='?page="&currentPage-1&"&keys="&keys&"&searchtype="&searchtype&"'>"&str_03&"</a>"'ASPCMS End
修改成:
'Feva StartfirstPageLink="<a href='?page=1&keys="&keys&"&searchType="&searchtype&conditionSearch& "'>"&str_01&"</a>" : lastPagelink="<a href='?page="&currentPage-1&"&keys="&keys&"&searchType="&searchtype&conditionSearch&"'>"&str_03&"</a>"'Feva End            

大功告成了,试过,没有错误 ASPCMS 2.5.4 beta 22014年7月28日
页: [1]
查看完整版本: ASPCMS多条件查询