first, it helps if you show us your REAL code.  The query statement you
showed below would obviously not work (it's missing the "mysql_query" part.
Second, when executing mysql_query() ALWAYS include the "or
die(mysql_error())" part to aid diagnostics.
Third, your query could not possibly work at the mysql command line; you've
misplaced the "AS" construct at the end of the query.

$maxid = "select max(tableid) as largestid from table";
$result = mysql_query($maxid) or die("Error: ".mysql_error());
list($mymaxidvalue) = mysql_fetch_array($result);
echo $mymaxidvalue;

-----Original Message-----
From: Jason McCormack [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 19, 2002 12:31 AM
Subject: [PHP-DB] Need Help with returning new id's

Hello All,

I am trying to return the largest id for a table and then print the value to
a page. My query works fine in MySQL, the problem is getting the value to
show in a web page with php. This is what I am trying to process.

1               | Test
2               | Test 2
3               | Test 3

In the sample table above I am trying to pull back a value of 3 and print to
a web page via php.

$maxid = "select max(tableid) from table as largestid";
// db_connect is my database connection. I know this works because I have
other pages that return
// results based on my queries without any problems
$run_query  = ($maxid,$db_connect);

This is were I get a bit lost. I have tried using all sorts of various mysql
functions without success

$row = mysql_fetch_row($run_query);
$mymaxidvalue = $row[0];
echo $mymaxidvalue;

As I stated above I have tried many different ways to get the desired
results but have been unsuccessful. Any help would be greatly appreciated.


PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to