Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2F3FE476DFE for ; Wed, 18 Dec 2002 16:35:14 -0500 (EST) Received: from petra.caravan.com (ns.caravan.com [209.128.88.97]) by postgresql.org (Postfix) with ESMTP id 66221476E66 for ; Wed, 18 Dec 2002 16:16:22 -0500 (EST) Received: from petra (localhost [127.0.0.1]) by petra.caravan.com (8.11.6/8.11.6) with ESMTP id gBILGNQ00583 for ; Wed, 18 Dec 2002 13:16:23 -0800 (PST) Date: Wed, 18 Dec 2002 13:12:28 -0800 To: Thorsten Haude Cc: pgsql-php@postgresql.org Subject: Re: pg_fetch_array() Message-Id: <20021218131228.13eb6d7d.waddell@caravan.com> In-Reply-To: <20021218203832.GI1604@eumel.yoo.local> References: <20021218203832.GI1604@eumel.yoo.local> Organization: caravan publishing X-Mailer: Sylpheed version 0.8.6 (GTK+ 1.2.10; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit From: Harry Waddell X-Delivery-Agent: TMDA/0.64 (Lawrin) Incoming: Harry Waddell X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/39 X-Sequence-Number: 1714 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