Jump to content

getting the last id, on another page


divinedesigns1

Recommended Posts

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

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 by Rollins
Link to comment
Share on other sites

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

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

  • 2 weeks later...
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

i made a query and order the id by desc which pulls the last id which was insert, thats the easiest way for me
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. Edited by birbal
  • Like 1
Link to comment
Share on other sites

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

still, it seems like the riskiest/fragile of all the options.

Edited by thescientist
Link to comment
Share on other sites

still, it seems like the riskiest/fragile of all the options.
true
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...