pg_fetch_array()
am 18.12.2002 21:38:32 von Thorsten Haude
Hi,
I want to read an unknown number of rows from a select result. I try
this:
- - - Schnipp - - -
$result = pg_exec($dbh, $statement);
$row = 0;
while ($item = pg_fetch_array($result, $row, PGSQL_ASSOC))
{
doSomething($item);
$row++;
}
- - - Schnapp - - -
However, I get an error telling me that PHP is "Unable to jump to row
[$nRows + 1] on PostgreSQL result index 3 in [$file] on line [$line]
What do I miss?
tia,
Thorsten
--
Denn ein Tyrann ist nicht, wenn die Masse nicht geduldig stillhält.
- Kurt Tucholsky
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: pg_fetch_array()
am 18.12.2002 22:12:28 von Harry Waddell
On Wed, 18 Dec 2002 21:38:32 +0100
Thorsten Haude wrote:
> Hi,
>
> I want to read an unknown number of rows from a select result. I try
> this:
> - - - Schnipp - - -
> $result = pg_exec($dbh, $statement);
> $row = 0;
> while ($item = pg_fetch_array($result, $row, PGSQL_ASSOC))
> {
> doSomething($item);
> $row++;
> }
> - - - Schnapp - - -
>
> However, I get an error telling me that PHP is "Unable to jump to row
> [$nRows + 1] on PostgreSQL result index 3 in [$file] on line [$line]
>
> What do I miss?
>
your using a while loop to process each result, but the last one which you
expect to return NULL/failure has to evaluate pg_fetch_array first with the
non-existent row index. You may be able to prepend @ to pg_fetch_array to
supress the warning [you should check that $result is not NULL also], but I'd
recommend using pg_NumRows and a for-loop instead.
--
Harry Waddell
Caravan Electronic Publishing
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: pg_fetch_array()
am 18.12.2002 22:36:12 von joerg.niemann
Thorsten Haude wrote:
>Hi,
>
>I want to read an unknown number of rows from a select result. I try
>this:
>- - - Schnipp - - -
>$result =3D pg_exec($dbh, $statement);
>$row =3D 0;
>while ($item =3D pg_fetch_array($result, $row, PGSQL_ASSOC))
>{
> doSomething($item);
> $row++;
>}
>- - - Schnapp - - -
>
>However, I get an error telling me that PHP is "Unable to jump to row
>[$nRows + 1] on PostgreSQL result index 3 in [$file] on line [$line]
This is a warning.
The warning occurence is the exit signal for the while statement.
If inside the while statement php is unable to jump to row x it
is the signal to exit the while statement.
Use pg_num_rows and for to avoid this.
for ($i=3D0; $i < pg_num_rows($result); $i++)
Joerg
--=20
=20
---------------------------------------
http://www.cityweb.de
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: pg_fetch_array()
am 18.12.2002 22:44:09 von Philipp Ottlinger
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
try @pg_fetch .... instead -
it will take away the message due to error message cancelling -
furthermore the loop finishes,
when there is an error ;-)
Thorsten Haude wrote:
|
| However, I get an error telling me that PHP is "Unable to jump to row
| [$nRows + 1] on PostgreSQL result index 3 in [$file] on line [$line]
|
| What do I miss?
|
|
| tia,
| Thorsten
- --
Philipp Ottlinger
cS Computer & Systeme GmbH
Menckenstr. 29
12169 Berlin
Tel. +49-30-79748317
Fax +49-30-7226748
E-Mail:ottlinger@computer-systeme.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+AOwnQogH4WkR2CwRAnB5AJ9qEBhP8g0c61TVnvPJkiWqCrAq/QCg ydgP
oVxb/gCqpiqdGgawpreu+A0=
=K+9g
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Re: pg_fetch_array()
am 18.12.2002 22:56:56 von Scott Marlowe
On Wed, 18 Dec 2002, Thorsten Haude wrote:
> Hi,
>
> I want to read an unknown number of rows from a select result. I try
> this:
> - - - Schnipp - - -
> $result = pg_exec($dbh, $statement);
> $row = 0;
> while ($item = pg_fetch_array($result, $row, PGSQL_ASSOC))
> {
> doSomething($item);
> $row++;
> }
> - - - Schnapp - - -
Wrap your while loop in this test:
if (pg_num_rows($result)>0){
}
It may be you're not getting any rows back here.
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: pg_fetch_array()
am 18.12.2002 23:03:29 von Thorsten Haude
Hi,
* Harry Waddell [2002-12-18 22:12]:
>Thorsten Haude wrote:
>> - - - Schnipp - - -
>> $result = pg_exec($dbh, $statement);
>> $row = 0;
>> while ($item = pg_fetch_array($result, $row, PGSQL_ASSOC))
>> {
>> doSomething($item);
>> $row++;
>> }
>> - - - Schnapp - - -
>>
>> What do I miss?
A clue-by-four, it seems.
>your using a while loop to process each result, but the last one which you
>expect to return NULL/failure has to evaluate pg_fetch_array first with the
>non-existent row index.
Of course. The only excuse I have is that I misread the documentation
in a really stupid way. (Not much of an excuse, is it?)
>You may be able to prepend @ to pg_fetch_array to supress the warning
>[you should check that $result is not NULL also], but I'd recommend
>using pg_NumRows and a for-loop instead.
Sure, I'll do that. I don't want to suppress anyone, much less
warnings.
Thanks for your patience.
Thorsten
--
Endorsing products is the American way of expressing individuality.
- Calvin
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/users-lounge/docs/faq.html
Re: pg_fetch_array()
am 18.12.2002 23:04:01 von Scott Marlowe
On Wed, 18 Dec 2002, Thorsten Haude wrote:
> Hi,
>
> I want to read an unknown number of rows from a select result. I try
> this:
> - - - Schnipp - - -
> $result = pg_exec($dbh, $statement);
> $row = 0;
> while ($item = pg_fetch_array($result, $row, PGSQL_ASSOC))
> {
> doSomething($item);
> $row++;
> }
> - - - Schnapp - - -
>
> However, I get an error telling me that PHP is "Unable to jump to row
> [$nRows + 1] on PostgreSQL result index 3 in [$file] on line [$line]
Sorry for the previously not quite right response. Since you are passing
in PGSQL_ASSOC you have to supply a row number, do it like this:
$stop = pg_num_rows($result);
for ($i=0;$i<$stop;$i++){
doSomething($item);
}
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: pg_fetch_array()
am 18.12.2002 23:55:40 von Thorsten Haude
Hi,
thanks to everyone who answered!
Thorsten
--
Good intentions will always be pleaded for every assumption of authority.
- Daniel Webster
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly