1、以下是ASP 取相关文章代码,可以通过后台增加关建字,然后前台通过SQL搜索语句查询出来。
Dim A:A = "手机,电脑,电视,硬盘"
Function sqlKeyWord(obj,field)
Dim temp:temp = split(obj,",")
For i = 0 To ubound(temp)
sqlKeyWord = sqlKeyWord & field&" like '%"&temp(i)&"%' or "
Next
sqlKeyWord = left(sqlKeyWord,len(sqlKeyWord)-3)
End Function
Dim xianguanSql:xianguanSql = "select id,title from [pingpai_title] where " + sqlKeyWord(A,"feilei")
取出SQL查询语句是:[pingpai_title] where feilei like '%手机%' or feilei like '%电脑%' or feilei like '%电视%' or feilei like '%硬盘%'
2、ASP替换拆分代码,可通过替换能解决常见的取包涵文章的方法。
Function key(eword)
eword = Replace(eword,",","','")
key = eword
End Function
xianguanText=key(rs("xianguan"))
xianguanSql="select top 12 * from [pingpai_title] where [feilei] in('"&xianguanText&"') Order By [paixu] asc"
这样就能解决in(‘’)里面的数据为 in('1','2','3',''4) ,这样就能取出数据。