ASPCMS 多条件查询

时间:2023-12-31 18:39:38

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"><a href="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"
' if not "0"=searchType then 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.[ImagePath],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 Start
Dim typeStr: typeStr=""
Dim searchType
searchType=filterPara(getForm("searchType","get"))
If isnul(searchType) Then searchType="0"
If Not "0"=searchType Then typeStr=" and a.SortID in (select {prefix}Sort.sortid from {prefix}Sort where sortType="&searchType&") "
If Not keys="all" Then
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.[ImagePath],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
Else
Dim formInput, keyValue, tempString : tempString = ""
For Each formInput In Request.QueryString
If Not formInput = "searchType" And Not formInput = "keys" And Not formInput = "page" Then
keyValue = filterPara(getForm(formInput, "get"))
If Len(keyValue) > 0 And Len(filterPara(formInput)) > 0 Then
tempString = tempString & " and " & formInput & " like '%" & keyValue & "%'"
End If
End If
Next
tempString = 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.[ImagePath],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&orderStr
End 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 Function
Else
Dim formInput, keyValue, tempString : tempString = ""
For Each formInput In Request.QueryString
If Not formInput = "searchType" And Not formInput = "keys" And Not formInput = "page" Then
keyValue = filterPara(getForm(formInput, "get"))
If Len(keyValue) > 0 And Len(filterPara(formInput)) > 0 Then
tempString = tempString & "&" & formInput & "=" & keyValue
End If
End If
Next
conditionSearch = tempString
Exit Function
' strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchType="&searchtype&tempString&""">"&pagenumber&"</a>"
End If
End Function
'Feva End

3. 修改"/inc/AspCms_CommonFun.asp",分页中部函数 Function makePageNumber(Byval currentPage,Byval pageListLen,Byval totalPages,Byval linkType,Byval sortid, Byval showType) 修改:

'ASPCMS  Start
' strPageNumber=strPageNumber&"<a href=""?page="&pagenumber&"&keys="&keys&"&searchtype="&searchtype&""">"&pagenumber&"</a>"
'ASPCMS End

修改成:

'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 Start
firstPageLink="<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 2  2014年7月28日