RE: [PHP-DB] Need Help with returning new id's

From: Date: Tue, 19 Mar 2002 21:33:46 +0000
Subject: RE: [PHP-DB] Need Help with returning new id's
Groups: php.db 
Request: Send a blank email to php-db+get-17767@lists.php.net to get a copy of this message
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:mccormack_j@hotmail.com] Sent: Tuesday, March 19, 2002 12:31 AM To: php-db@lists.php.net 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. TABLEID | VALUE 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. Thanks, Jason -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#17767) next »