Hi I am trying to do a select query in a select query but the page just hanged. I am using oracle as database. Is there any problem with Oracle?
sql = "bla bla bla" rs.Open sql, conn do while NOT rs.eof sql2 = "bla bla bla2" rs2.Open sql2, conn do while not rs2.eof Loop Loop Error
sql = "bla bla bla" rs.Open sql, conn do while NOT rs.eof sql2 = "bla bla bla2" rs2.Open sql2, conn do while not rs2.eof 'What is the need of this loop? rs2.MoveNext Loop rs.MoveNext Loop Code (markup):
are u sure it's endless loop bcuz the conditon is do while not rs.eof obviously when it reached the end, it stops. Does anybody has a loop like mine, post it here? Or is this kind of loop not possible in ASP? Then PHP ispossibly more powerful than ASP in terms of loop in a loop.
sql = "bla bla bla" rs.Open sql, conn do until rs.eof sql2 = "bla bla bla2" rs2.Open sql2, conn do until rs2.eof rs2.MoveNext loop rs.MoveNext loop Code (markup): Personally, that's how I would code it. The only thing is this: do until rs2.eof rs2.MoveNext loop Code (markup): I don't know for sure, but this bit of code seems a little useless? I mean, all it's doing is moving to the last record in the database... You could just use rs.MoveLast. If you're just trying to put a loop in a loop, then i'll assure you that you can put a loop in a loop: i = 0 e = 0 Do Until i = 10 i = i + 1 Response.Write("<br />this will be written a total of 10 times<br />") Do Until e = 10 e = e + 1 Response.Write("this will be written 10 times under each i, to a total of 100 times<br />") Loop e = 0 Loop Code (markup): Put that in a lone ASP file. I guarantee it will work
sql = "bla bla bla" rs.Open sql, conn do while NOT rs.eof sql2 = "bla bla bla2" rs2.Open sql2, conn do while not rs2.eof 'What is the need of this loop? rs2.MoveNext Loop [COLOR="Red"]rs2.close[/COLOR] rs.MoveNext Loop Code (markup): Please close rs1 and rs2 recordset after your loop is over.
Just realised what's wrong in general with this (don't know why I didn't think last night), but you shouldn't need to do a loop within a loop. You just need to code the select from the database different as in an outer join and an order by (or the oracle equivalent) and then use a single loop to output it.
the question is about query loop, not response loop. how does closing the record matters? i know there are procedures in oracle, but i'm trying to put away with that and code it with ASP. So it is not possible to do a loop in a loop query with ASP?
it is possible but generally pointless in any language/db, the reason being if you are pulling the records back from the database you just use an outer join to in effect do the second loop in the database. Because from a coding point of view it's highly highly inefficent to repeatedly query a database within a loop which is the result of a database query, as the join on the database side is considerably more efficent. As for closing the connection, in this case it's an issue because within the second loop you call Open each time you loop, this will mean that you will have as many connections open to your database as "number of loops for the first loop". So say you looped 100 times in the outer loop you would have over 100 open database connections "gulp!" (as in your IIS or apache server is connected 100 times to your db!) a sure way to kill your database when you get more than a few users at a time. Anyhow it's difficult to say more without seeing the code and db query, and admittedly I'm more an MS SQL server and .net guy than classic ASP (it's been over 8 years since I last touched that). But if you can post or pm me the code I'll have a look at it as soon as I can (maybe a day or two). But as a VERY VERY strong recommendation do your basic record processing on the database that's what it's designed for, and your user interaction/business logic in your server side code. hope that helps.