Received: from pgn.com ([198.107.240.10]) by postgresql.org (8.11.3/8.11.4) with SMTP id fAFMYlm56258; Thu, 15 Nov 2001 17:34:48 -0500 (EST) (envelope-from Culley_Harrelson@pgn.com) Received: from WIZ-Message_Server by pgn.com with Novell_GroupWise; Thu, 15 Nov 2001 14:34:47 -0800 Message-Id: X-Mailer: Novell GroupWise Internet Agent 5.5.4.1 Date: Thu, 15 Nov 2001 14:34:18 -0800 From: "Culley Harrelson" To: , Cc: , , , Subject: [PHP] Re: psql with PHP question Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=_F3A93117.117041B4" X-Archive-Number: 200111/612 X-Sequence-Number: 17606 This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=_F3A93117.117041B4 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Im sure it takes more memory but my preferred method is: $q =3D pg_Exec("SELECT id FROM article WHERE id=3D(SELECT MAX(id) FROM arti= cle)"); $data =3D pg_fetch_object ($q, 0); $maxid =3D $data->id; echo "The highest id is ". $maxid; To me this is more self-documenting and easier to maintian... culley >>> Philip Hallstrom 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 =3D pg_Exec("SELECT id FROM article WHERE id=3D(SELECT MAX(id) FROM > article)"); > $maxid =3D 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 =3D pg_Exec("SELECT id FROM article WHERE id=3D(SELECT MAX(id) > > FROM article)"); > > $maxid =3D 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 --=_F3A93117.117041B4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Description: HTML
Im sure it takes more memory but my preferred method=20 is:
 
$q =3D pg_Exec("SELECT id FROM article WHERE id=3D(SELE= CT MAX(id)=20 FROM article)");
$data =3D pg_fetch_object ($q, 0);
$maxid =3D=20 $data->id;
echo "The highest id is ". $maxid;
 
To me this is more self-documenting and easier to maintian...
 
culley

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

SELECT MAX(id) FROM=20 article

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

On Thu, 3 May 2001, Chris R= yan=20 wrote:

> Jason,
>
>     Look into the= =20 pg_result() function. You would use it something like
>=20 this:
>
> $q =3D pg_Exec("SELECT id FROM article WHERE id=3D(SE= LECT=20 MAX(id) FROM
> article)");
> $maxid =3D pg_result($q,0,0); #=20 pg_result($result,$row,$column_num)
> echo "The highest id is ".=20 $maxid[0];
>
>     Hope this helps.
>
&= gt;=20 Chris Ryan
> chris@greatbridge.com
>
> Jason wrote:
&g= t;=20 >
> > Hi, I want to try  and optimize my calls to postgreS= QL=20 from PHP.  If
> > I only need one field from a select stateme= nt,=20 what should I use?  I am
> > currently using:
> > $q= =3D=20 pg_Exec("SELECT id FROM article WHERE id=3D(SELECT MAX(id)
> > FRO= M=20 article)");
> > $maxid =3D pg_fetch_array($q, 0);
> > ech= o "The=20 highest id is ". $maxid[0];
> > What can I use besides an array to= get=20 a single value? In general, using
> > a single variable always sav= es=20 more memory than using an array?  Thank
> > you.
> >= =20 Jason
> >
> > ---------------------------(end of=20 broadcast)---------------------------
> > TIP 5: Have you checked = our=20 extensive FAQ?
> >
> > http://www.po= stgresql.org/users-lounge/docs/faq.html
>
>=20 ---------------------------(end of broadcast)--------------------------->=20 TIP 3: if posting/reading through Usenet, please send an appropriate
>= ;=20 subscribe-nomail command to majordomo@postgresql.org so that your
>= =20 message can get through to the mailing list=20 cleanly
>


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




---------------------------(en= d of=20 broadcast)---------------------------
TIP 4: Don't 'kill -9' the=20 postmaster
--=_F3A93117.117041B4--