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? Link to comment https://forums.phpfreaks.com/topic/259898-update-one-column-question/ 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)"); Link to comment https://forums.phpfreaks.com/topic/259898-update-one-column-question/#findComment-1332075 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 ^^ Link to comment https://forums.phpfreaks.com/topic/259898-update-one-column-question/#findComment-1332079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.