scott212 Posted January 25, 2007 Share Posted January 25, 2007 Is there an easy way to get the row number of a row I just inserted? Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 Did you check the manual? [url=http://php.net/mysql_insert_id]mysql_insert_id[/url](). Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted January 25, 2007 Share Posted January 25, 2007 If you've just inserted it, then you can do this:[code]<?php$query=mysql_query("SELECT COUNT(*) FROM table_name");$result=mysql_result($query,0);echo $result;?>[/code]As it'll be the last row, just find out how many rows there are. If you want to do it at a later time, then this won't work because other rows may have been inserted. You could use:[code]<?php$query=mysql_query("SELECT id FROM table_name WHERE something=$something");$result=mysql_fetch_assoc($query);echo $result;?>[/code]This'll work all the time, but only if you have one of the pieces of data stored somewhere, like in a SESSION variable. Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted January 25, 2007 Share Posted January 25, 2007 Ignore me, as thorpe pointed out, you can use mysql_insert_id() which is much easier... Quote Link to comment Share on other sites More sharing options...
scott212 Posted January 25, 2007 Author Share Posted January 25, 2007 Sorry guys, I know, rtfm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.