Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    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

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    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.
    Last edited by BubikolRamios; 01-20-2013 at 05:10 PM.
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •