pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Culley Harrelson <Culley_Harrelson@pgn.com>
To: philip@adhesivemedia.com
To: beloshapka@mnogo.ru
Cc: gee308@mediaone.net
Cc: pgsql-general@postgresql.org
Cc: pgsql-novice@postgresql.org
Cc: pgsql-php@postgresql.org
Subject: [PHP] Re:  psql with PHP question
Date: Thu, 15 Nov 2001 14:34:18 -0800
Message-ID: <sbf3d287.009@pgn.com> (raw)

Im sure it takes more memory but my preferred method is:

$q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) FROM article)");
$data = pg_fetch_object ($q, 0);
$maxid = $data->id;
echo "The highest id is ". $maxid;

To me this is more self-documenting and easier to maintian...

culley

>>> Philip Hallstrom <philip@adhesivemedia.com> 05/03/01 08:29AM >>>
Also... is there any reason you don't just do:

SELECT MAX(id) FROM article

rather than what you have below?  It would get you the same thing wouldn't
it and save a query...

On Thu, 3 May 2001, Chris Ryan wrote:

> Jason,
>
>     Look into the pg_result() function. You would use it something like
> this:
>
> $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) FROM
> article)");
> $maxid = pg_result($q,0,0); # pg_result($result,$row,$column_num)
> echo "The highest id is ". $maxid[0];
>
>     Hope this helps.
>
> Chris Ryan
> chris@greatbridge.com
>
> Jason wrote:
> >
> > Hi, I want to try  and optimize my calls to postgreSQL from PHP.  If
> > I only need one field from a select statement, what should I use?  I am
> > currently using:
> > $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id)
> > FROM article)");
> > $maxid = pg_fetch_array($q, 0);
> > echo "The highest id is ". $maxid[0];
> > What can I use besides an array to get a single value? In general, using
> > a single variable always saves more memory than using an array?  Thank
> > you.
> > Jason
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
>
> ---------------------------(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
>


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)




---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

view thread (12+ messages)

Message-ID: <sbf3d287.009@pgn.com>
Permalink:  ../sbf3d287.009@pgn.com/
Also on:    postgresql.org/message-id/sbf3d287.009@pgn.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: Culley_Harrelson@pgn.com, philip@adhesivemedia.com, beloshapka@mnogo.ru, gee308@mediaone.net, pgsql-general@postgresql.org, pgsql-novice@postgresql.org
  Subject: Re: [PHP] Re:  psql with PHP question
  In-Reply-To: <sbf3d287.009@pgn.com>
  References: <sbf3d287.009@pgn.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox