divinedesigns1 Posted April 4, 2013 Share Posted April 4, 2013 hello alllll, btw thank everyone who been helping me.Question: is it possible to get the last inserted id on a different file? say you have you.php which insert everything then u have meme.php which echo out everything, is it possible for meme.php to get the last inserted id? because im trying to do that but im not getting back the last inserted id, instead i got back 0 which means it did not get anything in return so my question is, how can i get the last inserted id on meme.php Link to comment Share on other sites More sharing options...
Rollins Posted April 4, 2013 Share Posted April 4, 2013 (edited) you can store the inserted data in a session....echo that in meme.php or use data as a reference for the query on you.php. you can do a second query on you.php to request the id with the inserted as reference in the where clause....store that in a session. guess if you use 'SELECT LAST(id) you could get back the wron id... there are other functions in sql but i never used any....check the answers from stackoverflow.com. looks quit complete.... Edited April 4, 2013 by Rollins Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 4, 2013 Author Share Posted April 4, 2013 you can store the inserted data in a session....echo that in meme.php or use data as a reference for the query on you.php. you can do a second query on you.php to request the id with the inserted as reference in the where clause....store that in a session. guess if you use 'SELECT LAST(id) you could get back the wron id... there are other functions in sql but i never used any....check the answers from stackoverflow.com. looks quit complete....thank but i got it working Link to comment Share on other sites More sharing options...
Rollins Posted April 4, 2013 Share Posted April 4, 2013 thank but i got it working how did you resolve this? i went for a second query to get the id after the insert because it was the easiest solution for me at that time... Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 13, 2013 Author Share Posted April 13, 2013 how did you resolve this? i went for a second query to get the id after the insert because it was the easiest solution for me at that time...i made a query and order the id by desc which pulls the last id which was insert, thats the easiest way for me Link to comment Share on other sites More sharing options...
birbal Posted April 13, 2013 Share Posted April 13, 2013 (edited) i made a query and order the id by desc which pulls the last id which was insert, thats the easiest way for meThat would not be accurate all time. tarffic heavy/ or moderately heavy site where there is concurrent insertion the value will be changed till user request again page. mysql function LAST_INSERT_ID() will give you last inserted id accurately. It gives last inserted id of current connection. incase you need to pass the id to other page it can be sent via GET,COOKIE,POST,SESSION as you would do with passing other id. Edited April 13, 2013 by birbal 1 Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 13, 2013 Author Share Posted April 13, 2013 That would not be accurate all time. tarffic heavy/ or moderately heavy site where there is concurrent insertion the value will be changed till user request again page. mysql function LAST_INSERT_ID() will give you last inserted id accurately. It gives last inserted id of current connection. incase you need to pass the id to other page it can be sent via GET,COOKIE,POST,SESSION as you would do with passing other id.it wouldnt be high traffic thats why i used that Link to comment Share on other sites More sharing options...
thescientist Posted April 13, 2013 Share Posted April 13, 2013 (edited) still, it seems like the riskiest/fragile of all the options. Edited April 13, 2013 by thescientist Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 14, 2013 Author Share Posted April 14, 2013 still, it seems like the riskiest/fragile of all the options.true Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now