Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building an array using rs.RecordCount

Status
Not open for further replies.

timcadieux

Programmer
May 25, 2005
129
BE
Folkz, I get the recordCount from my db, and i need to populate some information, currently i'm doing this..

Code:
var photos=new Array()
photos[0]="[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(0)%>"[/URL]
photos[1]="[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(1)%>"[/URL]
photos[2]="[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(2)%>"[/URL]
photos[3]="[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(3)%>"[/URL]
photos[4]="[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(4)%>"[/URL]

but if my recordCount is say 10, how could i dynamically build this into my code?
 
This is probably better suited for the ASP forum. However, I'll try my best.
(For the record I use JScript for all my server side ASP coding, so I'm pretty VBScript illiterate. I'll provide a server side JScript solution but it should be easy to convert to VBScript)
Code:
<%
Response.Write("var photos = new Array()");
for (i = 0; i < rs.RecordCount; i++) {
   Response.Write('photos[' + i + ']="[URL unfurl="true"]http://test/cls_images/lores/'[/URL] + Series_Dir + '/' + pic[i] + '"');
}
%>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
You can use a loop server-side to do this. Assuming you're using J(ava)Script to program your ASP pages (if not, you'd need to go and ask this in the VBScript forum), it would be something like:

Code:
var photos = new Array();
<% for (var loop=0; loop<recordCount; loop++) { %>
photos[<%=loop%>] = '[URL unfurl="true"]http://test/cls_images/lores/<%=Series_Dir%>/<%=pic(loop)%>';[/URL]
<% } %>

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
A slight ammendment to my solution:
Code:
<%
Response.Write("var photos = new Array()[COLOR=red][b]\n[/b][/color]");
for (i = 0; i < rs.RecordCount; i++) {
   Response.Write('photos[' + i + ']="[URL unfurl="true"]http://test/cls_images/lores/'[/URL] + Series_Dir + '/' + pic[i] + '"[COLOR=red][b]\n[/b][/color]');
}
%>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
That's awesome, i didn't know you code do that, but i guess it just makes sense. thx, i'll give it a try!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top