MySQL Forums
Forum List  »  Newbie

Re: last record query
Posted by: Dave Smith
Date: March 02, 2005 08:39PM

I am confused. You say that you want just the last record, but you use 'id >= LAST_INSERT_ID()' and you use a loop to display the results.

Is '$user' you? If so, then there can be no records greater then your LAST_INSERT_ID() value - unless you have torn down and created a new connection between your update and this query.

LAST_INSERT_ID() is connection-specific; meaning that it will be zero until you actually insert data into a table on this connection. So, what might be happening, is that you are inserting data, tearing down and creating a new connection, and then running this query. If you are, that explains the results you are seeing.

Do you want to see the last record that you entered or the last record that anybody entered. If the latter, then use

SELECT * FROM tbl WHERE Name = '$user' ORDER BY id LIMIT 1

Dave

Options: ReplyQuote


Subject
Written By
Posted
March 02, 2005 08:10PM
Re: last record query
March 02, 2005 08:39PM
March 02, 2005 08:57PM
March 03, 2005 09:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.