View Single Post
  #5 (permalink)  
Old April 3rd, 2009, 08:41 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

So how come your original posted code doesn't work???

Let's look at it again. With minor corrections/adaptations.

Code:
<script type="text/javascript">
function banner( image, number, url )
{ 
     ... this is the constructor for a banner ...
}

var pic = new Array( );
<%
Set conn = server.createobject("adodb.connection")
conn.open "DSN=XXXX" ' If possible, AVOID using DSN's for connections!!!
sql="Select bannerImage, bannerNumber, bannerURL from table"
Set rs = conn.Execute( sql )
counter = 0;
Do Until rs.EOF
    image = rs("bannerImage")
    num   = rs("bannerNumber")
    url   = rs("bannerURL")
%>
    pic[<%=counter%>] = new banner("<%=image%>","<%=num%>","<%=url%>");
<%
    counter = counter + 1
    rs.MoveNext
Loop
rs.close
%>
Now, there *IS* a slightly more elegant way to do this, which is also a little faster, but it's harder to follow.

Code:
<script type="text/javascript">
function banner( image, number, url )
{ 
     ... this is the constructor for a banner ...
}

<%
Set conn = server.createobject("adodb.connection")
 conn.open "DSN=XXXX" ' If possible, AVOID using DSN's for connections!!!
sql="Select bannerImage, bannerNumber, bannerURL from table"
Set rs = conn.Execute( sql )
prefix = "new banner("""
midfix = ""","""
suffix1 = """)"
suffix2 = "," & vbNewLine

jsData = rs.getString( , , midfix, suffix1 & suffix2 & prefix )
jsData = prefix & Left( jsData, Len(jsData) - Len(suffix2) - Len(prefix) )

rs.Close
%>
var pic = new Array(
<%=jsData%>
    );
Here's an old FAQ I wrote that explains the above.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
rtr1900 (April 13th, 2009)