| DanInMa |
01-30-2013 04:54 PM |
appending to string variable while looping through records
This is my code. I am trying to add html for an acnhor link, to a string variable, each time a record is looped through in a recordset. If its the first record the html is slightly different.
My code as written only adds the first anchor, as if its ignoring the else in my if else statement based on the current recordset index.
- the code not working as expected is highlighted in red.
Code:
function view_NSMC_News(arg1)
dim mn,mnheader,mnfooter,mn_imgsrc,mn_title,mn_url,mn_content,objConn,objRs,sql,overlayPH,SlideNavHeader,SlideNavSquaresArray()
mnheader = "<div id=""slideshow"">"& vbCrLF
overlayPH = "<div id=""slideroverlay""> </div>"& vbCrLF
SlideNavHeader = "<div id=""slidenav"">"& vbCrLF
Response.Write mnheader
err.clear
On Error Resume Next
set objConn=server.CreateObject("ADODB.Connection")
objConn.ConnectionTimeout=5
objConn.Open testdsn
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.Open "SELECT TOP "&arg1&" * FROM dbo.[12_NEWS] ORDER BY NEWID()", objConn, 3, 1
if Err.Number <> 0 then
Response.write("<div class=""article img_left""><img src=""/images/nsmcconnect/blank.png"" width=""150"" height=""150"" alt=""No Image"" /><h2>Error Occured</h2><p>"&err.description&"</p></div>")
else
if objRs.BOF then
response.write("<div class=""article img_left""><img src=""/images/nsmcconnect/blank.png"" width=""150"" height=""150"" alt=""No Image"" /><h2>No Articles Found</h2><p>No current articles are posted at this time.</p></div>")
else
Do While Not objRs.EOF
mn_id = objRs("ID_News")
mn_imgsrc = "/images/news/mainnews/"+objRs("Image1")
mn_title = objRs("Title")
mn_content = objRs("Article")
mn_url="/"
if objRS.Index = 0 then
SlideNavSquares = "<a href=""/"" class=""active""> </a>"& vbCrLF
else
SlideNavSquares = SlideNavSquares & "<a href="/"> </a>"& vbCrLF
end if
Response.write("<a href="""&mn_url&""" class=""active"" alt="""&mn_title&"""><img src="""&mn_imgsrc&""" />"& vbCrLF)
Response.write("<div>"&mn_content&"<span class=""readmore"">> Read More</span></div></a>"& vbCrLF)
objRs.MoveNext
Loop
end if
end if
objRs.close
objConn.Close
Set objConn=Nothing
Response.Write overlayPH
Response.Write SlideNavHeader
Response.Write SlideNavSquares
Response.write(" </div>" & vbCrLF & " </div>")'closing #slidenav
On Error GoTo 0
end function
if I change the number on objRS.Index = 0 , the results are the same as if it's not really checking it or something.
If I change to this
Code:
if objRS.Index = 0 then
SlideNavSquares = SlideNavSquares & "<a href=""/"" class=""active""> </a>"& vbCrLF
else
SlideNavSquares = SlideNavSquares & "<a href="/"> </a>"& vbCrLF
end if
I get 2 html anchors, but the second anchor is incorrect, as if objRS.Index is matching 0 on every loop.. man im confused!
|