Can you really do this code in PHP? Unless your PHP code pulls out all
of the data and finishes running through the first query before entering
the while loop, you would get a similar error in PHP. Or, maybe you're
calling pconnect() a couple of times in PHP, which effectively opens up
two DB connections in this case.
The issue is that your database connection $db is busy: you're still
looping through the results of your first query. Thus, you cannot issue
a second query using that DB connection. You need two connections.
Your code needs to look like:
set db_list [ns_db gethandle "foobar" 2]
set db1 [lindex $db_list 0]
set db2 [lindex $db_list 1]
and then you can use db1 for the outer query, and db2 for the inner query.
Note that you should generally consider if you can do this in one query,
using a join. It's not always possible or the best solution, but
oftentimes it will be.
-Ben
Roman Fiser wrote:
> Hello AOLServer users,
>
> I have following problem:
>
> set db [ns_db gethandle "foobar"]
> set sel [ns_db select $db "SELECT foo FROM bar"]
> while {[ns_db getrow $db $sel]} {
> .....
> set sel2 [ns_db select $db "SELECT bar FROM foo"]
> ns_db getrow $db $sel2
> .....
> }
>
> After second loop of first "while", aolserver said:
> Get row called outside fetch row loop.
>
> I'm new to AOLServer and similar code works fine for me under Apache+PHP.
>
> I'm using AOLServer 3.4, PostgreSQL 7.1.2, pgdriver 2.0 from openacs on my
> Debian GNU/Linux (i686)
>
> Thanx for your advice and sorry for my ugly english :)
>
> --
> Best regards,
> Roman "RoFi" Fiser
> [EMAIL PROTECTED]
>
> TrimCon s.r.o., Czech republic
>
> ICQ: 2554226
> Cell: +420 (605) 215216
> Web: www.management.cz