I have a table where I need to figure out the very first ID and the
very last ID, so here is what I wrote:
$first_query = "SELECT id FROM mytable ORDER BY id LIMIT 1";
$first_result = mysql_query($first_query,$con);
$first_id = mysql_result($first_result,0,'id');
$last_query = "SELECT id FROM
SELECT MIN(id), MAX(id) FROM mytable
:)
Hope that helps!
-TG
= = = Original message = = =
I have a table where I need to figure out the very first ID and the
very last ID, so here is what I wrote:
$first_query = "SELECT id FROM mytable ORDER BY id LIMIT 1";
$first_result = mysql_query($firs
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> SELECT MIN(id), MAX(id) FROM mytable
As an aside, is you are using associative arrays, be sure to use the
following keys:
$array['MIN(id)'] and $array['MAX(id)']
Just something I figured out recently :)
Matt
--
PHP Database Mail
Sounds about right... you can also do something like this (syntax should be
right):
SELECT MIN(id) as minid, MAX(id) as maxid FROM mytable
$array['minid'] and $array['maxid']
Basically it's going to be whatever the heading of that column is. Using "as"
gives it an alias for less ugly headin
On Wed, 11 Jul 2007, Matt Leonhardt wrote:
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
SELECT MIN(id), MAX(id) FROM mytable
As an aside, is you are using associative arrays, be sure to use the
following keys:
$array['MIN(id)'] and $array['MAX(id)']
Just something I figured o