andrewgarn Posted July 22, 2008 Share Posted July 22, 2008 Hi I'm having problems with my code where my update queries update more than one row, I want it to only update one row, will LIMIT 0, 1 prevent it from updating more than 1 row? Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/ Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 in order to update only 1 row, you need a where clause in your update query that specifies unique data for that row, like an id# or something, that's unique for that row. example: id name 0 adam 1 mark 2 julie 3 adam update table set name = 'james' where id = 0 would result in this: id name 0 james 1 mark 2 julie 3 adam Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596936 Share on other sites More sharing options...
andrewgarn Posted July 22, 2008 Author Share Posted July 22, 2008 i'm using an id at the moment but somehow my old data keeps getting updated with todays date Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596945 Share on other sites More sharing options...
andrewgarn Posted July 22, 2008 Author Share Posted July 22, 2008 could an update script updating a talbe called records without using `` around the table name cause multiple rows to be updated? Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596948 Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 no... perhaps the problem is with your table structure. Perhaps you have your "date" column setup to automatically update to the current timestamp upon updating or something? Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596956 Share on other sites More sharing options...
andrewgarn Posted July 22, 2008 Author Share Posted July 22, 2008 no... perhaps the problem is with your table structure. Perhaps you have your "date" column setup to automatically update to the current timestamp upon updating or something? How do I check that? and i understood there was a problem with updating table name record without `` as it was a mysql word Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596964 Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 well, I mean yeah, if your table name is a mysql reserved word, then you do need to use backticks around it (or better yet, choose a different table name, as that's poor coding), but that's not what would cause multiple rows to be updated. Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596969 Share on other sites More sharing options...
andrewgarn Posted July 22, 2008 Author Share Posted July 22, 2008 ok thanks guess i need to look elsewhere for the bug closed for now Quote Link to comment https://forums.phpfreaks.com/topic/116088-solved-update-add-only-1-row/#findComment-596990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.