Clinton Posted February 12, 2009 Share Posted February 12, 2009 Ok, I use this code to insert a record into the db... $result = mysql_query("INSERT INTO ply (did, rn, cltr, eid, jid, cdate) VALUES ('$did', '$rn', '$cltr', '$eid', '$jid', '$cdate')"); Now, when this inserts it does an automatic auto-increment on an 'id' column that is not listed. Is there a way that I can turn right back around after this gets inserted and get the corresponding id number? Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/ Share on other sites More sharing options...
mike12255 Posted February 12, 2009 Share Posted February 12, 2009 you could try this: $newitems = mysql_query ("SELECT * FROM ply ORDER BY id DESC LIMIT 1") Might have to be asc but im pretty sure its desc btw no promises on that im not the best at mysql Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/#findComment-760242 Share on other sites More sharing options...
PFMaBiSmAd Posted February 12, 2009 Share Posted February 12, 2009 http://us3.php.net/mysql_insert_id Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/#findComment-760243 Share on other sites More sharing options...
printf Posted February 12, 2009 Share Posted February 12, 2009 Something like... mysql_query(INSERT query here...); echo mysql_insert_id(); Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/#findComment-760244 Share on other sites More sharing options...
mike12255 Posted February 12, 2009 Share Posted February 12, 2009 hey thanks PFMaBiSmAd i've never heard of that, im sure it'll help me too! Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/#findComment-760245 Share on other sites More sharing options...
Clinton Posted February 12, 2009 Author Share Posted February 12, 2009 mysql_insert_id() <-- didn't know that existed. Thanks for all the replies and ideas. Link to comment https://forums.phpfreaks.com/topic/144873-solved-insert-and-retrieve/#findComment-760247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.