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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.