Jump to content

update query not working


MDanz

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/238604-update-query-not-working/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.