Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: RE: Randomise


Message #1 by Sam Clohesy <sam@e...> on Mon, 17 Dec 2001 16:29:16 -0000
Hi all. wondering if anyone can tell me what I am doing wrong here:



Depending on a keyword (from a search form) a banner is displayed. The

banner is randmised so more than one company can sponsor a keyword. If there

are no sponsoring keywords then a default banner appeears.



The problem is that even if there is no corresponding banner when I put my

randomise code in the default banner does not display but the random banner

does. Do i need to encapsulate the random code in a function and call it

under a condition?? (I am going a bit mental here)



Here is my code:



im strUserPicPath

strUserPicPath = ("/article-images")



Dim  objFSO

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")



if session("siteId") = "" then

session("siteID") = request.querystring("id")

end if



Dim newpath

newpath = ("_private/banners")



Dim strBannerPath

strBannerPathWeb = "../_private/banners/"



Dim strWebLinks

strWebLink = "advertise.asp?adOpt=1"



Dim objrsSite1



set objRsSite1 = server.createobject("ADODB.Recordset")

strSqlSite = "SELECT * FROM tblSite WHERE siteId = " & session("siteID")

objRsSite1.open strSqlSite, objConn, 2



session ("sitename") = objRsSite1("sitename")

session ("siteFranchisee") = objRsSite1 ("siteFranchisee")



Dim txtSearch

request.querystring ("txtSearch")

'txtSearch = trim(server.urlencode((request.querystring ("txtSearch"))))





set objRsKey= server.createobject("ADODB.Recordset")

Dim objrsKey

strSqlKey = "SELECT * FROM tblBanner WHERE siteId = " & session("siteID") &

" AND keyword LIKE '%" & txtSearch & "%'"

objRsKey.open strSqlKey, objConn, 3





if (objrsKey.BOF and objrsKey.EOF) then

response.write "<a href = '" & strWebLink & "'><img src = ' " &

strBannerPathWeb & "/lnet_banner.gif' border = '0'></a>"

end if



if NOT (objrsKey.BOF and objrsKey.EOF) then			

'

     ' Generating random number from total number of records

    Dim intRnd

      Randomize Timer

      intRnd = (Int(RND * objrsKey.RecordCount))



      ' Now moving the cursor to random record number

      objrsKey.Move intRnd



      ' Showing the random statement

      'Response.Write "<b>" & objrsKey("BannerID") & "</b>"









				   If objFSO.FileExists(newPath & "/" &

objRsKey("bannerID") & ".jpg") Then

				   'If checkfile(newPath & "\" &

objrsKey("bannerID") & ".jpg",False) = 1 Then

				   	response.write "<a href = '" &

objrsKey ("bannerLink") & "' target = 'new'>" 

					response.Write "<img src='" &

newpath & "/" & objrsKey("bannerID") & ".jpg" & "'"

					response.write " border = '0'></a>"

					response.write objrsKey("BannerID")

else



					If

objFSO.FileExists(Server.Mappath(newPath) & "/" & objRsKey("bannerID") &

".gif") Then

					response.write "<a href = '" &

objrsKey ("bannerLink") & "' target = 'new'>"

					response.Write "<img src='" &

newpath & "/" & objrsKey("bannerID") & ".gif" & "'"

					response.write " border = '0'></a>"

					response.write objrsKey("BannerID")

					response.write "<p></p>"

					response.write objrsKey.recordcount

					response.write "<p></p>"

					response.write objrsKey("keyword")

					response.write "<p></p>"

					response.write txtSearch

					else



					

				   end If

				   end if

				   end if

				   





				  

				   objrsSite1.close

				   set objrsSite1 =nothing

				   objrsKey.Close

				   Set objrsKey = nothing

				   Set objFSO = nothing

Message #2 by "Ken Schaefer" <ken@a...> on Wed, 19 Dec 2001 13:39:34 +1100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Sam Clohesy" <sam@e...>

Subject: [asp_web_howto] RE: Randomise





: Depending on a keyword (from a search form) a banner is displayed. The

: banner is randmised so more than one company can sponsor a keyword. If

there

: are no sponsoring keywords then a default banner appeears.

:

: The problem is that even if there is no corresponding banner when I put my

: randomise code in the default banner does not display but the random

banner

: does.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



I don't believe this last part. I believe that something else is wrong with

your logic. Have you thought of putting in a few Response.Write() calls

throughout your code to see where the code is falling to?



Cheers

Ken




  Return to Index