Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 03:53 PM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,526
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
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.



.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-20-2013, 02:37 AM   PM User | #2
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Code:
WHERE advert_id in (id1,id2,...) ?
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search
BubikolRamios is offline   Reply With Quote
Old 01-20-2013, 02:13 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,526
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Never heard of that

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.


.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-20-2013, 05:06 PM   PM User | #4
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Quote:
Originally Posted by jeddi View Post
Never heard of that
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.
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search

Last edited by BubikolRamios; 01-20-2013 at 05:10 PM..
BubikolRamios is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:20 AM.


Advertisement
Log in to turn off these ads.