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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better to have 10 Recordsets or loop through the same one 10 times 2

Status
Not open for further replies.

bryant89

Programmer
Nov 23, 2000
150
CA
I need an expert opinion on what I should do. I have an asp page where I want to retrieve records but I have to place certain records under certain headings. So I need write the heading then output the records. In order to do this I need to go through all the records ten times for each heading. should I create a recordset for each heading or loop through the same one 10 times

By the way I know I should be ordering the records in the sql query so I would not have to run through all of the records but in this case I cannot.

Any help would be appreciated
Thanks
Bryant
 
if you are looping, just to find the headings, and the headings are in the recordset, and you know how to identify them, and it is based on SQL (maybe even access) you can create a query (select * from etc, so forth) to pull back just the headings.

but even then, I dont see why you need to loop ten times for heading, it would sound like only twice (one time to grab all the headings, then second time to display what's what)

etc, I'll probally think of something more efficient as the day goes on. Karl Blessing
aka kb244{fastHACK}
 
ooops I guess I wasnt to clear... I will try an example

there are records being returned with an id and a name

When id 105 comes up the associated name has to be put under one heading

so I output the heading first in html
then I loop through the whole recordset gathering all the ids with 105 and output the associated names. But they all have to be under that heading

then I output another heading in html
this time I need all the names that associate with the number 106 to be output...


And so on....

I hope this helps.
Thanks for the help Karl
 
I found a way where I can use ten boolean variables to ensure the heading only gets output once and that way the recordset on gets looped through once but if you can think of something better I would really appreciate it
 
Bryant,

> By the way I know I should be ordering the records in the sql query
> so I would not have to run through all of the records but in this
> case I cannot.

Are you sure? It sounds like you have the relationships to order the query. Could you post the pertinent parts of your schema?

-pete
 
Looping through a recordset multiple times is infinitely faster than re-opening or opening multiple recordsets.

Placing the result set in an array, then traversing that could be faster still.

Creating a number of arrays, one for each heading, and stuffing the recordset values into the appropriate array would be fastest. The page would then dump out the array values, rather than recordset values - and the recordset would only be traversed once.
 
Thanks for the tip Merlin.
I will definately look into a traversal. Thanks for the help
I appreciate it very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top