Forums

ASP

This topic is locked

repeat records x times

Posted 13 Jan 2009 18:18:47
1
has voted
13 Jan 2009 18:18:47 Chris Brown posted:
Hi,

I am happily using DW with repating regions, but what I want is a little more specific...

If I have a recordset with say 10 records in it, I want the recordset to repeat again say 5 times (starting from the 1st record) effectively giving me 5 lots of the same 10 records (50 records in total).

I am using MY SQL 4 and I cannot seem to find a repeat for SQL, otherwise I would do it in SQL rather than in ASP.

Can anyone help with this. Below is a sample of the type of output I am after should the above not be clear! I have done this example on just 3 records repeating 3 time to save me typing too much!

1. record 1
2. record 2
3. record 3
4. record 1
5. record 2
6. record 3
7. record 1
8. record 2
9. record 3
10. record 1
11. record 2
12. record 3

thanks!

Replies

Replied 04 Feb 2009 13:13:49
04 Feb 2009 13:13:49 Andrew Watson replied:
Many many wasy to achieve this...but as it always should you should think about performance....

An array is processed much faster than a recordset by asp....less overheads...so you could use the ado GETROWS method to make a multidimensional array from your recordset..then simply use a for loop to go through it...

Nest this inside another for loop for your multiple repeat...e.g
dim objConn, rsData, arrData
set objConn = 'your connection string'
set rsData = objConn.execute([i]your sql statement[/i])
if not rsData.eof then
arrData = rsData.getrows
end if

for cntRepeat = 0 to 4 (repeat them 5 times)
 for cntRow = 0 to ubound(arrData,2)
  --> spit out your record e.g. response.write arrData(0,cntRow) for first field
 next
next


or just use...

rs.movefirst then so the repeating region again...

theres quality examples on w3schools for this...

cheers
AW

Edited by - on 04 Feb 2009 13:15:06
Replied 10 Feb 2009 11:54:24
10 Feb 2009 11:54:24 Chris Brown replied:
Thanks very much, I will look into both options.

Cheers.

Reply to this topic