⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search_process.asp

📁 简单的asp论坛源码系统,很适用于初学者!界面简洁,功能齐全
💻 ASP
📖 第 1 页 / 共 3 页
字号:
		
		'Else this is a search of the post
		Else
			'Set the field name for the SQL query
			strTableFieldName = strDbTable & "Thread.Message"
			
			
			'If displaying results in topic view use a sub query
			If strResultType = "topics" Then
				
				strSQLwhereKeywords = strSQLwhereKeywords & "" & _
				"AND (" & strDbTable & "Topic.Topic_ID " & _
					"IN (" & _
						"SELECT " & strDbTable & "Thread.Topic_ID " & _
						"FROM " & strDbTable & "Thread" & strDBNoLock & " " & _
						"WHERE " 
			End If
			
		End If
		
		'Create the SQL
		'If this is a phrase search then check for the phrase
		If strSearchType = "phrase" Then
			'If searching in topic view then don't use AND as it is a sub query
			If strResultType = "topics" AND strSearhIn = "body" Then 
				strSQLwhereKeywords = strSQLwhereKeywords & " (" & strTableFieldName & " LIKE '%" & strSearchKeywords & "%')"
			Else
				strSQLwhereKeywords = strSQLwhereKeywords & "AND (" & strTableFieldName & " LIKE '%" & strSearchKeywords & "%')"
			End If
			'Check length
			If Len(strSearchKeywords) <= intSearchWordLength Then blnSearhWordsTwoShort = True
		
		'Else this is a Any Words or All Words search
		Else
		
			'If this is a search for Any Words use 'OR' for SQL
			If strSearchType = "anyWords" Then
				strSQLoperator = "OR"
			'Else if this is a search of All Words use 'AND' for the SQL
			Else
				strSQLoperator = "AND"
			End If
			
			'Split the search keywords and place into an array
			sarySearchWord = Split(Trim(strSearchKeywords), " ")
			
			'Build the SQL search query
			'If displaying results as topics then don't use AND
			If strResultType = "topics" AND strSearhIn = "body" Then
				strSQLwhereKeywords = strSQLwhereKeywords & " ("
			Else
				strSQLwhereKeywords = strSQLwhereKeywords & "AND ("
			End If
			
			'Loop through all the selected forums
			For intCurrentRecord = 0 To UBound(sarySearchWord)
				
				'If this is 2nd or more time around add OR
				If intCurrentRecord > 0 Then strSQLwhereKeywords = strSQLwhereKeywords & " " & strSQLoperator & " " 
				
				'Add the keyword to look in to the SQL query
				strSQLwhereKeywords = strSQLwhereKeywords & strTableFieldName & " LIKE '%" & sarySearchWord(intCurrentRecord) & "%'"
			
				'Check length of keywords
				If Len(sarySearchWord(intCurrentRecord)) <= intSearchWordLength Then blnSearhWordsTwoShort = True
			Next
			
			strSQLwhereKeywords = strSQLwhereKeywords & ") "
			
			'Reset record count
			intCurrentRecord = 0	
		End If
		
		'If displaying results in topic view then check if the message is hidden and close sub query
		If strResultType = "topics" AND strSearhIn = "body" Then
			If blnModerator = false AND blnAdmin = false Then 
				strSQLwhereKeywords = strSQLwhereKeywords & "AND (" & strDbTable & "Thread.Hide=" & strDBFalse & " "
				If intGroupID <> 2 Then strSQLwhereKeywords = strSQLwhereKeywords & "OR " & strDbTable & "Thread.Author_ID=" & lngLoggedInUserID
				strSQLwhereKeywords = strSQLwhereKeywords & ") "
			End If
			strSQLwhereKeywords = strSQLwhereKeywords & _
				")" & _
			") "
		End If
	End If
	
	
	
	
	'******************************************
	'***   	SQL for member search		***
	'******************************************
	
	'SQL for member search
	If strMemberName <> "" Then
		
		'Get rid of milisous code
		strMemberName = formatSQLInput(strMemberName)
		
		'Check length of member name
		If Len(strMemberName) <= intSearchWordLength Then blnSearhWordsTwoShort = True
		
		'If displaying results in topic view use a sub query
		If strResultType = "topics" Then
			
			'Create SQL for member search, using a sub query so we can get all the topics the member has posted in
			strSQLwhereMemSearch = strSQLwhereMemSearch & _
			"AND (" & strDbTable & "Topic.Topic_ID " & _
				"IN (" & _
					"SELECT " & strDbTable & "Thread.Topic_ID " & _
					"FROM " & strDbTable & "Thread" & strDBNoLock & ", " & strDbTable & "Author" & strDBNoLock & " " & _
					"WHERE " & strDbTable & "Thread.Author_ID=" & strDbTable & "Author.Author_ID "
					
					
			'Create the SQL for the member search, either exact match or LIKE match
			If blnExactUserMatch Then
		 		strSQLwhereMemSearch = strSQLwhereMemSearch & "AND (" & strDbTable & "Author.Username='" & strMemberName & "') "
			Else
				strSQLwhereMemSearch = strSQLwhereMemSearch & "AND (" & strDbTable & "Author.Username LIKE '" & strMemberName & "%') "
			End If
			
			'If display hidden posts to admin, modertors, and those who posted them
			If blnModerator = false AND blnAdmin = false Then 
				strSQLwhereMemSearch = strSQLwhereMemSearch & " AND (" & strDbTable & "Thread.Hide=" & strDBFalse & " "
				If intGroupID <> 2 Then strSQLwhereMemSearch = strSQLwhereMemSearch & " OR " & strDbTable & "Thread.Author_ID=" & lngLoggedInUserID 
				strSQLwhereMemSearch = strSQLwhereMemSearch &  ") "
			End If
			strSQLwhereMemSearch = strSQLwhereMemSearch & _
				")" & _
			") "
		
			
		'Else results as shown in 'post' view so don't use the sub query (would also be faster)
		Else
			'Create the SQL for the member search, either exact match or LIKE match
			If blnExactUserMatch Then
		 		strSQLwhereMemSearch = strSQLwhereMemSearch & "AND (" & strDbTable & "Author.Username='" & strMemberName & "') "
			Else
				strSQLwhereMemSearch = strSQLwhereMemSearch & "AND (" & strDbTable & "Author.Username LIKE '" & strMemberName & "%') "
			End If
		
		End If
		
	End If
	
	
	
	
	'******************************************
	'***   	SQL for date search		***
	'******************************************
	
	'If a date is selected build the SQL string for the date
	If intShowTopicsFrom <> 0 Then
		
		'Start the SQL for the date
		If strResultType = "topics" Then
			strSQLwhereDate = "AND (LastThread.Message_date"
		Else
			strSQLwhereDate = "AND (" & strDbTable & "Thread.Message_date"
		End If
		
		'Set the direction, (posts before or after date requested)
		If strDateDirection = "newer" Then
			strSQLwhereDate = strSQLwhereDate & ">"
		Else
			strSQLwhereDate = strSQLwhereDate & "<"
		End If
		
		
		'If Access use # around dates, other DB's use ' around dates
		If strDatabaseType = "Access" Then
			strSQLwhereDate = strSQLwhereDate & "#"
		Else
			strSQLwhereDate = strSQLwhereDate & "'"
		End If
		
		'Initialse the string to display when active topics are shown since
		Select Case intShowTopicsFrom
			Case 1
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(dtmLastVisitDate)
			Case 2
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("d", -1, now()))
			Case 3
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("ww", -1, now()))
			Case 4
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("m", -1, now()))
			Case 5
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("m", -2, now()))
			Case 6
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("m", -6, now()))
			Case 7
				strSQLwhereDate = strSQLwhereDate & internationalDateTime(DateAdd("yyyy", -1, now()))
		End Select
		
		'If SQL server remove dash (-) from the ISO international date to make SQL Server safe
		If strDatabaseType = "SQLServer" Then strSQLwhereDate = Replace(strSQLwhereDate, "-", "", 1, -1, 1)
		
		'If Access use # around dates, other DB's use ' around dates
		If strDatabaseType = "Access" Then
			strSQLwhereDate = strSQLwhereDate & "#"
		Else
			strSQLwhereDate = strSQLwhereDate & "'"
		End If
		
		strSQLwhereDate = strSQLwhereDate & ") "	
	End If
	

	
	'******************************************
	'***   	SQL for forum ID search		***
	'******************************************
	
	'Set the forums to look in, if not looking in all forums
	If Trim(Mid(strForumIDs, 1, 1)) <> "0" AND strForumIDs <> "" Then
		
		strSQLwhereForum = strSQLwhereForum & " AND " & strDbTable & "Forum.Forum_ID IN ("
		
		'Loop through all the selected forums
		For each iarySearchForumID in Request.Form("forumID")
			
			'If this is 2nd or more time around add OR
			If intCurrentRecord > 0 Then strSQLwhereForum = strSQLwhereForum & "," 
			
			'Add the forum ID to look in to the SQL query
			strSQLwhereForum = strSQLwhereForum & CInt(iarySearchForumID)
			
			'Add 1 to the current record position counter
			intCurrentRecord = intCurrentRecord + 1
		Next
		
		strSQLwhereForum = strSQLwhereForum & ") "
		
		'Reset record count
		intCurrentRecord = 0
	End If
	
	
	
	'******************************************
	'***   	SQL for Topic ID search		***
	'******************************************
	
	'Set the forums to look in, if not looking in all forums
	If Request.Form("qTopic") Then 
		
		strSQLwhereForum = strSQLwhereForum & " AND " & strDbTable & "Topic.Topic_ID = " & lngTopicID & " "
		
	End If
	
	
	
	'******************************************
	'***   	Main SQL Query			***
	'******************************************
	
	
	'If displaying results as topics then more data is required and a different query needs to be run
	If strResultType = "topics" Then
	
		'Initalise SQL query (quite complex but required if we only want 1 db hit to get the lot for the whole page)
		strSQL = "" & _
		"SELECT "
		If strDatabaseType = "SQLServer" OR strDatabaseType = "Access" Then
			strSQL = strSQL & " TOP " & intMaxResults & " "
		End If
		strSQL = strSQL & _
		"" & strDbTable & "Forum.Forum_ID, " & strDbTable & "Forum.Forum_name, " & strDbTable & "Forum.Password, " & strDbTable & "Forum.Forum_code, " & strDbTable & "Topic.Topic_ID, " & strDbTable & "Topic.Poll_ID, " & strDbTable & "Topic.Moved_ID, " & strDbTable & "Topic.Subject, " & strDbTable & "Topic.Icon, " & strDbTable & "Topic.Start_Thread_ID, " & strDbTable & "Topic.Last_Thread_ID, " & strDbTable & "Topic.No_of_replies, " & strDbTable & "Topic.No_of_views, " & strDbTable & "Topic.Locked, " & strDbTable & "Topic.Priority, " & strDbTable & "Topic.Hide, " & strDbTable & "Thread.Message_date, " & strDbTable & "Thread.Message, " & strDbTable & "Thread.Author_ID, " & strDbTable & "Author.Username, LastThread.Message_date, LastThread.Author_ID, LastAuthor.Username, " & strDbTable & "Topic.Event_date, " & strDbTable & "Topic.Event_date_end " & _
		"FROM " & strDbTable & "Category" & strDBNoLock & ", " & strDbTable & "Forum" & strDBNoLock & ", " & strDbTable & "Topic" & strDBNoLock & ", " & strDbTable & "Thread" & strDBNoLock & ", " & strDbTable & "Thread AS LastThread" & strDBNoLock & ", " & strDbTable & "Author" & strDBNoLock & ", " & strDbTable & "Author AS LastAuthor" & strDBNoLock & " " & _
		"WHERE " & strDbTable & "Category.Cat_ID = " & strDbTable & "Forum.Cat_ID " & _
			"AND " & strDbTable & "Forum.Forum_ID = " & strDbTable & "Topic.Forum_ID " & _

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -