Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f06KuI707048 for ; Sat, 6 Jan 2001 15:56:18 -0500 (EST) (envelope-from pgsql-general-owner@postgresql.org) Received: from smtp3.a2000.nl (deviet-f.a2000.nl [62.108.1.240] (may be forged)) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f061FD754543 for ; Fri, 5 Jan 2001 20:15:13 -0500 (EST) (envelope-from gravity@node10065.a2000.nl) Received: from node10065.a2000.nl ([24.132.0.101]) by smtp3.a2000.nl with esmtp (Exim 2.05 #7) id 14EhxB-0001ic-00; Sat, 6 Jan 2001 02:15:29 +0100 Received: (from gravity@localhost) by node10065.a2000.nl (8.8.7/8.8.7) id CAA24227; Sat, 6 Jan 2001 02:15:28 +0100 Date: Sat, 6 Jan 2001 02:15:28 +0100 From: gravity@node10065.a2000.nl To: Uro Gruber Cc: pgsql-general@postgresql.org Subject: Re: PHP and PostgreSQL Message-ID: <20010106021528.C24049@node10065.a2000.nl> Reply-To: gravity@dds.nl References: <631076786.20010105231729@sir-mag.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <631076786.20010105231729@sir-mag.com>; from uros@sir-mag.com on Fri, Jan 05, 2001 at 11:17:29PM +0100 X-Archive-Number: 200101/243 X-Sequence-Number: 2416 On Fri, Jan 05, 2001 at 11:17:29PM +0100, Uro Gruber wrote: > Hi! > I have some questions about coding in php with postgre. > Here is my code > $qu = pg_exec ($db_conn, "SELECT * FROM clients ORDER BY username"); > $row = 0; // postgres needs a row counter other dbs might not > while ($data = @pg_fetch_object ($qu, $row)) { > echo $data->username." ("; > echo $data->password ."): "; > echo $data->client_id."
"; > $row++; > } > When i execute this i get 3 records (in DB is also 3 records), if i > delete @ before pg_fetch_object i get an error: > "Unable to jump to row 3 on PostgreSQL result index 4" > I understand what's wrong and i know why is that @. > What i do want to know is, if there is something wrong with this > function or am i doing something wrong. I don't like that kind of > errors. How can i stop before the end. > In mysql there was no need to count rows. there are nicer ways (look for one in the db-abstraction layer in PHP-LIB) but this works: > $qu = pg_exec ($db_conn, "SELECT * FROM clients ORDER BY username"); $number_of_rows = pg_numrows($qu); for ($counter=0;$counter<$number_of_rows;$counter++) { $data_array = pg_fetch_array($qu, $counter); echo "$data_array[username]"; } z.