Nested select to same tsble
am 18.11.2002 08:06:05 von Andy DunlopThis is a multi-part message in MIME format.
------=_NextPart_000_0015_01C28EE1.B9AB6B00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I hope you won't mind helping me here: (I have searched the Postgres mailin=
g lists but no-one seems to have had this problem) None of the documentatio=
n seems to address this:
Is this legal?
$sSql =3D "select glatype, gla.glacode, gladescrip, gladepr, gll.*
from gll,gla
where gll.glacode =3D gla.glacode
and gla.glatype =3D '".strtoupper($glrowresult)."'
and gll.fisyear =3D $year
order by gll.glacode";
$result1 =3D pg_exec($conn, $sSql);
for($i=3D0;$i
$glresult =3D pg_fetch_array($result1,$i);
if($glresult["glatype"]=="FA")
{
$sSql=3D"select * from gll
where gll.glacode =3D '".strtoupper($glresu=
lt["gladepr"])."'
and gll.fisyear =3D $year";
The second select does not work - it gives no error message either. I wonde=
r if it does not like selecting a seond time from gll while in the loop aft=
er the first select. The idea is that some gl accounts need to refer to oth=
er ones for a calculation to be done during this report I am trying to do.
Thanks
_________________________________
Andy Dunlop
mailto:andy@horizon.co.za
Office: +27 (21) 975 2440
Cell: +27 (82) 770 8749
_________________________________
------=_NextPart_000_0015_01C28EE1.B9AB6B00
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
have=20
searched the Postgres mailing lists but no-one seems to have had this probl=
em)=20
None of the documentation seems to address this:
adescrip,=20
gladepr,=20
gll.*
=
=20
from=20
gll,gla
&nbs=
p; =20
where gll.glacode =
gla.glacode
=
=20
and gla.glatype =
'".strtoupper($glrowresult)."'
 =
; =20
and gll.fisyear =
$year
=
=20
order by gll.glacode";
$resul=
t1 =
pg_exec($conn, $sSql);
=20
for($i=3D0;$i<pg_numrows($result1);$i++)
&nbs=
p; =20
{
&nbs=
p; =20
$glresult =
pg_fetch_array($result1,$i);
&=
nbsp; =20
if($glresult["glatype"]=="FA")
&=
nbsp; =20
{
&=
nbsp;=20
$sSql=3D"select * from=20
gll
&n=
bsp;  =
; =20
where gll.glacode =
'".strtoupper($glresult["gladepr"])."'
&nb=
sp; =
&nb=
sp;=20
and gll.fisyear =3D $year";
The second select does not work - it g=
ives no=20
error message either. I wonder if it does not like selecting a seond time f=
rom=20
gll while in the loop after the first select. The idea is that some gl acco=
unts=20
need to refer to other ones for a calculation to be done during this report=
I am=20
trying to do.
Andy=
=20
Dunlop
href=3D"mailto:andy@horizon.co.za">mailto:andy@horizon.co.za V>
2440
Cell: +27 (82) 770=20
8749
_________________________________
------=_NextPart_000_0015_01C28EE1.B9AB6B00--
Re: Nested select to same tsble
am 18.11.2002 18:19:34 von Keary Suskaon 11/18/02 12:06 AM, andy@horizon.co.za purportedly said:
> $sSql = "select glatype, gla.glacode, gladescrip, gladepr, gll.*
> from gll,gla
> where gll.glacode = gla.glacode
> and gla.glatype = '".strtoupper($glrowresult)."'
> and gll.fisyear = $year
> order by gll.glacode";
> $result1 = pg_exec($conn, $sSql);
> for($i=0;$i
> $glresult = pg_fetch_array($result1,$i);
> if($glresult["glatype"]=="FA")
> {
> $sSql="select * from gll
> where gll.glacode = '".strtoupper($glresult["gladepr"])."'
> and gll.fisyear = $year";
>
> The second select does not work - it gives no error message either. I wonder
> if it does not like selecting a seond time from gll while in the loop after
> the first select. The idea is that some gl accounts need to refer to other
> ones for a calculation to be done during this report I am trying to do.
There are no restrictions on the number of concurrent select results, other
then RAM and disk space. Remember, once a command is exec'ed, the database
returns the *entire* result to the client (PHP), and is no longer involved.
That is why you can close a connection to a database and still work with the
result.
Anyway, you certainly can do this, and if it isn't working, there's probably
something wrong with the code or your assumptions about the query results.
Use print() statements so you can follow the code.
Remember, you cannot redefine $result1, i.e. use that variable for storing
results from the second query.
Why do you not simply combine the queries into a single query join? It would
be more efficient that way.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org