Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 topic.asp - TopicNav - DB Queries
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 October 2002 :  11:55:03  Show Profile
File: topic.asp

Lines 469-473
Addition of Statement in red will save two database queries
if strShowTopicNav = "1" then
        dim prevTopic, nextTopic
	Call Topic_nav()
else
	Response.Write("Topic")
end if

CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain

It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.

Prayer Of Forgiveness
"I forgive all living beings. May all living beings forgive me!
I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated)

work mule
Senior Member

USA
1358 Posts

Posted - 01 October 2002 :  21:38:42  Show Profile
Okay, I'll be the sucker that asks the obvious dumb question.

Why? (Just curious...)
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 October 2002 :  21:50:53  Show Profile
<edit>to reduce scroll<edit>

quote:
Originally posted by work mule II

Okay, I'll be the sucker that asks the obvious dumb question.

Why? (Just curious...)



Following statements occur twice in topic.asp
Lines 469-473 and Lines 714-718


	if strShowTopicNav = "1" then
		Call Topic_nav()
	else
		Response.Write("Topic")
	end if


The sub Topic_nav() is called twice. Since the variables nextTopic and prevTopic are local to sub they do not hold the information obtained from the db between the two calls to the sub. so they are = "" each time a call is made to the sub. Declaring variables at script level will keep the variables populated with the info obtained from the DB first time.
Sub Topic_nav()    

	if prevTopic = "" then
		strSQL = "SELECT T_SUBJECT, TOPIC_ID "
		strSql = strSql & "FROM " & strActivePrefix & "TOPICS "
		strSql = strSql & "WHERE T_LAST_POST > '" & Topic_LastPost
		strSql = strSql & "' AND FORUM_ID = " & Forum_ID
		strSql = strSql & " AND T_STATUS < 2"  ' Ignore unapproved/held posts
		strSql = strSql & " ORDER BY T_LAST_POST;"

		set rsPrevTopic = my_conn.Execute(TopSQL(strSql,1))

		if rsPrevTopic.EOF then
			prevTopic = getCurrentIcon(strIconBlank,"","align=""top"" hspace=""6""")
		else
			prevTopic = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & _
rsPrevTopic("TOPIC_ID") & """>" & _
getCurrentIcon(strIconGoLeft,"Previous Topic","align=""top"" hspace=""6""") & "</a>"
		end if

		rsPrevTopic.close
		set rsPrevTopic = nothing
	else
		prevTopic = prevTopic
	end if

	if NextTopic = "" then		strSQL = "SELECT T_SUBJECT, TOPIC_ID "
		strSql = strSql & "FROM " & strActivePrefix & "TOPICS "
		strSql = strSql & "WHERE T_LAST_POST < '" & Topic_LastPost
		strSql = strSql & "' AND FORUM_ID = " & Forum_ID
		strSql = strSql & " AND T_STATUS < 2"  ' Ignore unapproved/held posts
		strSql = strSql & " ORDER BY T_LAST_POST DESC;"

		set rsNextTopic = my_conn.Execute(TopSQL(strSql,1))

		if rsNextTopic.EOF then
			nextTopic = getCurrentIcon(strIconBlank,"","align=""top"" hspace=""6""")
		else
			nextTopic = "<a href=""topic.asp?" & ArchiveLink & "TOPIC_ID=" & _
rsNextTopic("TOPIC_ID") & """>" & _
getCurrentIcon(strIconGoRight,"Next Topic","align=""top"" hspace=""6""") & "</a>"
		end if

		rsNextTopic.close
		set rsNextTopic = nothing
	else
		nextTopic = nextTopic
	end if
	Response.Write ("                " & prevTopic & "<b><font face=""" & _
strDefaultFontFace & """ size=""" & _
strDefaultFontSize & """ color=""" & _
strHeadFontColor & """> Topic </font></b>" & nextTopic)

end sub

Edited by - GauravBhabu on 01 October 2002 22:51:04
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.61 seconds. Powered By: Snitz Forums 2000 Version 3.4.07