...

View Full Version : How should I do a multiple update ?



jeddi
01-19-2013, 04:53 PM
Hi,

I would like to update FIVE records a once.

I usually do one at a time like this:


$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


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, 03:37 AM
WHERE advert_id in (id1,id2,...) ?

jeddi
01-20-2013, 03:13 PM
Never heard of that :eek:

So I write:


$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, 06:06 PM
Never heard of that :eek:


That is definitely right syntax.

Example:



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum