kigogu Posted March 28, 2012 Share Posted March 28, 2012 Hi, I was wondering if there was a way to do a single update for one column but for multiple rows? To clarify, I have an array that holds the id of multiple rows and I want to update these rows with a single value in one go instead of having to loop through my array and then doing an update. Right now I have: foreach ($found as &$value) { mysql_query("UPDATE account SET found = 1 WHERE id = '" . $value . "'"); } is there any way to get rid of the foreach loop and just have mysql_query("UPDATE ....")? or at least a faster and more efficient way of doing this? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 28, 2012 Share Posted March 28, 2012 Use mysql in() $ids = array(23,234,242,12,234,1234); $idstr = implode(",", $ids); mysql_query("UPDATE account SET found = 1 WHERE id in($idstr)"); Quote Link to comment Share on other sites More sharing options...
kigogu Posted March 28, 2012 Author Share Posted March 28, 2012 lol thank you xP i actually just found that and i was coming back here to say that i found the answer. but thank you for your reply ^^ Quote Link to comment 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.