Thread: Resource id #3?

Resource id #3?

From
Mark Nelson
Date:
I guess I'm not getting this, but I'm trying to run an
aggregate function (MAX) on a simple table with PHP. I want
to find the largest id (an integer) and nothing else. It
doesn't matter what is in that row, I just want the largest.
I thought I had it with this:

$maxid = query("SELECT MAX(id) FROM mytable");

// query () is a function that queries the DB with the sql

But when I echo "$maxid"; I get "Resource id #3". That is
not what I wanted. I was hoping I would get "25" or "30" or
whatever the highest number in the 'id' column is. What am I
missing here?

/mark



Re: Resource id #3?

From
Philip Hallstrom
Date:
It looks like that is the result id (like it says :) for that particular
query.  You now need to do something like:

$max_value = get_value($maxid);

query isn't the standard postgres function... it's pg_query, so I'm not
sure what else is going on...  check the postgresql section of the PHP
manpage for more info.

-philip

On Tue, 5 Nov 2002, Mark Nelson wrote:

>
> I guess I'm not getting this, but I'm trying to run an
> aggregate function (MAX) on a simple table with PHP. I want
> to find the largest id (an integer) and nothing else. It
> doesn't matter what is in that row, I just want the largest.
> I thought I had it with this:
>
> $maxid = query("SELECT MAX(id) FROM mytable");
>
> // query () is a function that queries the DB with the sql
>
> But when I echo "$maxid"; I get "Resource id #3". That is
> not what I wanted. I was hoping I would get "25" or "30" or
> whatever the highest number in the 'id' column is. What am I
> missing here?
>
> /mark
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: Resource id #3?

From
Josh Berkus
Date:
Mark,

> I guess I'm not getting this, but I'm trying to run an
> aggregate function (MAX) on a simple table with PHP. I want
> to find the largest id (an integer) and nothing else. It
> doesn't matter what is in that row, I just want the largest.
> I thought I had it with this:

There is a PGSQL-PHP mailing list, which you should join and post your PHP
questions there.

--
-Josh Berkus
 Aglio Database Solutions
 San Francisco