MDanz Posted June 7, 2011 Share Posted June 7, 2011 this query isn't working. foreach($rating as $value) //foreach loop which updates totalsum every array key { if($value>0) { $totalsum = mysql_query("UPDATE block SET totalsum=totalsum+$value WHERE id=$d",$this->connect); } } i echoed the query and get this UPDATE block SET totalsum=totalsum+2 WHERE id=16 AND id=17 AND id=18 AND id=19 it should work. I have entries in mysql with those id's. It should update the totalsum column by 2 for those id's Quote Link to comment https://forums.phpfreaks.com/topic/238604-update-query-not-working/ Share on other sites More sharing options...
requinix Posted June 7, 2011 Share Posted June 7, 2011 UPDATE block SET totalsum=totalsum+2 WHERE id=16 AND id=17 AND id=18 AND id=19 Look at that. If id=16 then it can't possibly=17 can it? And if it =17 then it can't possibly =16. You want IN. UPDATE block SET totalsum=totalsum+2 WHERE id IN (16, 17, 18, 19) $ids = array(16, 17, 18, 19); $query = "UPDATE block SET totalsum=totalsum+2 WHERE id IN (" . implode(", ", $ids) . ")"; Remember to make sure you actually have IDs, otherwise the query will crash. Quote Link to comment https://forums.phpfreaks.com/topic/238604-update-query-not-working/#findComment-1226195 Share on other sites More sharing options...
MDanz Posted June 7, 2011 Author Share Posted June 7, 2011 thanks it works. learned something new. Quote Link to comment https://forums.phpfreaks.com/topic/238604-update-query-not-working/#findComment-1226199 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.