ASP专题

aspcms多条件检索例子——ASPCMS实例

其实asp中的多条件查询已经不是神马难的事情,基本的思路大家都知道,我就不详细说明。

title=request("title") 
type1=request("type123") 
content=request("content")
sqls="where id>0" 
if title<>"" then sqls=sqls&" and title123 like '%"&title&"%' "
if type1<>"" then sqls=sqls&" and type1 like '%"&type1&"%' "
if content<>"" then sqls=sqls&" and content35 like '%"&content&"%' "
sql="select * from news_info "&sqls&" order by ID asc"
以上是简单的思路,大家可以根据自己的数据库进行书写,我今天要说的是关于一个简单好用的asp程序,他的名字就叫ASPCMS,我想很多人都在用,开源的系统,界面很简单整洁,但是要是用他原来的思路实现多条件查询还是要找很多的地方,我也是花了一个小时才找到,把过程分享出来。
第一在页面中加入搜索,我以搜索标题和作者为例

第二在根目录下找到search.asp,在加以下代码



<%
echoContent()
Sub echoContent()
	dim page,keys,author
	page=filterPara(getForm("page","both"))
	keys=filterPara(getForm("keys","both"))
	author=filterPara(getForm("author","both"))
	if isNul(keys) then alertMsgAndGo "请输入标题","-1"
	if isNul(page) then page=1
	if isNum(page) then page=clng(page) else echoMsgAndGo "页面不存在",3 end if
	
	dim templateobj,channelTemplatePath : set templateobj=new TemplateClass
	dim typeIds,rsObj,rsObjtid,Tid,rsObjSmalltype,rsObjBigtype
	Dim templatePath,tempStr	
	templatePath=sitePath&"/"&"templates/"&setting.defaultTemplate&"/"&setting.htmlFilePath&"/search.html"	
	'die templatePath
	if not CheckTemplateFile(templatePath) then echo "search.html"&err_16

	with templateObj 
		.content=loadFile(templatePath)	
		.parseHtml()
		.parseCommon() 		
		.parseList 0,page,"searchlist",keys,author,"searchlist"		
		echo .content 
	end with
	set templateobj =nothing : terminateAllObjects
End Sub
%>

以上标注新增代码的就是需要修改的地方

 

还有打开执行的文件 inc\AspCms_MainClass.asp

在1179行,也可以查找Public Function parseList

添加

Public Function parseList(typeIds,currentPage,pageListType,keys,author,showType)

在sql语句中添加

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 a.SortID in (“&getSubSort(typeIds, 1)&”) and Title like ‘%”&keys&”%’ and Author like ‘%”&author&”%'” &typeStr&orderStr

这件就可以实现多条件检索的,当然还有很多方法,这个是不改变原来的基础上添加的。

Avatar photo

人生长恨水长东

留言

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据