CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   How should I do a multiple update ? (http://www.codingforums.com/showthread.php?t=286068)

jeddi 01-19-2013 03:53 PM

How should I do a multiple update ?
 
Hi,

I would like to update FIVE records a once.

I usually do one at a time like this:

PHP Code:

$sql "UPDATE adverts SET views = viewS+1 lastviewed = '$today' WHERE advert_id = $this_ad";

mysql_query($sql) or die("could not UPDATE adverts - BlockType B "mysql_error()); 


The 5 adverts have ids

PHP Code:

advert_id $ad_A;
advert_id $ad_B;
advert_id $ad_C;
advert_id $ad_D;
advert_id $ad_E

How should I do a multiple update ?
Do I insert a series of AND's ?

Thanks.



.

BubikolRamios 01-20-2013 02:37 AM

Code:

WHERE advert_id in (id1,id2,...) ?

jeddi 01-20-2013 02:13 PM

Never heard of that :eek:

So I write:

PHP Code:

$sql "UPDATE adverts SET views = viewS+1 lastviewed = '$today' WHERE advert_id = ($ad_A, $ad_B, $ad_C, $ad_D, $ad_E)"

mysql_query($sql) or die("could not UPDATE adverts - BlockType B "mysql_error()); 

Is that going work ?

If not - how should it be done ?

Thanks.


.

BubikolRamios 01-20-2013 05:06 PM

Quote:

Originally Posted by jeddi (Post 1307570)
Never heard of that :eek:

That is definitely right syntax.

Example:

Code:

update test set c = c+1 where b in (1,2)
The PHP part is your to do as I, myself do things in java.


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.