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? Link to comment https://forums.phpfreaks.com/topic/35620-get-mysql-row-number-for-new-row/ 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](). Link to comment https://forums.phpfreaks.com/topic/35620-get-mysql-row-number-for-new-row/#findComment-168701 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. Link to comment https://forums.phpfreaks.com/topic/35620-get-mysql-row-number-for-new-row/#findComment-168703 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... Link to comment https://forums.phpfreaks.com/topic/35620-get-mysql-row-number-for-new-row/#findComment-168705 Share on other sites More sharing options...
scott212 Posted January 25, 2007 Author Share Posted January 25, 2007 Sorry guys, I know, rtfm. Link to comment https://forums.phpfreaks.com/topic/35620-get-mysql-row-number-for-new-row/#findComment-168709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.