Re: Nested select to same tsble

From: Keary Suska <hierophant(at)pcisys(dot)net>
To: Postgres-PHP <pgsql-php(at)postgresql(dot)org>
Subject: Re: Nested select to same tsble
Date: 2002-11-18 17:19:34
Message-ID: B9FE6F36.15796%hierophant@pcisys.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

on 11/18/02 12:06 AM, andy(at)horizon(dot)co(dot)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<pg_numrows($result1);$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"

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Keary Suska 2002-11-18 17:48:31 Re: Inquiry From Form [pgsql]
Previous Message scott.marlowe 2002-11-18 17:12:40 Re: Inquiry From Form [pgsql]