RE: [PHP] Selecting max(id) of a table
| From: | Sam Masiello | Date: | Mon, 22 Jan 2001 21:50:40 +0000 |
| Subject: | RE: [PHP] Selecting max(id) of a table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-36088@lists.php.net to get a copy of this message | ||
Try this:
$result=mysql_query('select max(id) as max_id from mytable');
$max=mysql_result($result, 0, 'max_id');
print ('Max id in the table=$max');
HTH
Sam Masiello
Systems Analyst
Chek.Com
(716) 853-1362 x289
smasiello@chekinc.com
-----Original Message-----
From: Chakravarthy K Sannedhi [mailto:san_kalyan@yahoo.com]
Sent: Monday, January 22, 2001 4:44 PM
To: php-general@lists.php.net
Subject: [PHP] Selecting max(id) of a table
Hello all,
I am having a table named 'mytable' of 5 rows in a
MySQL database. I tried to print '5' which is the
highest row onto the screen. I used the following code
for that:
$result=mysql_query('select max(id) from mytable');
$max=mysql_result($result);
print ('Max id in the table=$max');
But what all i am getting is an error like below:
Warning:Wrong parameter count for mysql_result() in
/home/httpd/info.php on line xx
Max id in the table=$max
i am confused about which function to use instead of
mysql_result().
please help
Chakravarthy K Sannedhi
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net