amites Posted January 31, 2008 Share Posted January 31, 2008 extra question for the night: any way for me to update more than one entry in a single query? I want to set a timestamp and add to a counter, hoping I don't have to do it in 2 queries for the sake of the DB... many thanks Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/ Share on other sites More sharing options...
pdkv2 Posted January 31, 2008 Share Posted January 31, 2008 i am not getting what exactly you want to do . Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-454206 Share on other sites More sharing options...
fenway Posted January 31, 2008 Share Posted January 31, 2008 Provided you want to update all the records the same way, yes. Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-454455 Share on other sites More sharing options...
amites Posted February 1, 2008 Author Share Posted February 1, 2008 I suppose it would have helped if I posted some code with my question, $query = "UPDATE bil_msg_sent AS s" . "\n JOIN bil_msg_look AS l ON (l.locid = s.locid)" . "\n JOIN bil_users AS u ON (u.id = s.userid)" . "\n JOIN bil_location AS loc ON (l.locid = loc.id)" . "\n SET s.last_read = now()" . "\n WHERE s.msg_date BETWEEN l.look_date - INTERVAL 1 hour AND l.look_date + INTERVAL 1 hour" . "\n AND s.active = 1" . "\n AND l.active = 1" I'd also like to update field "s.read" to equal "s.read + 1" though I'm not certain how to do that one, any suggestions would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-455597 Share on other sites More sharing options...
fenway Posted February 3, 2008 Share Posted February 3, 2008 You can say s.read = s.read + 1, but that's not necessarily thread-safe. Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-457016 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 if it is an auto increment field, don't use sread+1. you have to retrieve the next increment, which is a little harder. let me know if you need help with that. Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-457219 Share on other sites More sharing options...
amites Posted February 4, 2008 Author Share Posted February 4, 2008 it's not an autoincrement field, it's just an int field used to count the number of times the record has been accessed, Quote Link to comment https://forums.phpfreaks.com/topic/88690-update-multiple-entries-in-1-query-possible/#findComment-457731 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.