Re: pg_fetch_array()

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Thorsten Haude <postgresql(at)thorstenhau(dot)de>
Cc: PostgreSQL PHP ML <pgsql-php(at)postgresql(dot)org>
Subject: Re: pg_fetch_array()
Date: 2002-12-18 22:04:01
Message-ID: Pine.LNX.4.33.0212181501190.4045-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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);
}

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Mark Nelson 2002-12-18 22:29:03 getting table names
Previous Message Thorsten Haude 2002-12-18 22:03:29 Re: pg_fetch_array()