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

    Should I be using AND or OR

    Hi,

    I am not sure of the logic of this.

    I am trying to update several records with different record ids.

    So I have this:


    PHP Code:
    $sql "UPDATE pios SET jds= jds+1 WHERE 
    ( id = $id1 AND id = $id2 AND id = $id3 AND id = $id4)"

    OR should it be:



    PHP Code:
    $sql "UPDATE pios SET jds= jds+1 WHERE 
    ( id = $id1 || id = $id2 || id = $id3 || id = $id4)"


    Or something else ?

    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
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    AND would be a refinement of existing criteria. Assuming ID is unique or primary, than AND would be impossible since you cannot have records with ID = 1 AND id = 2. That would use an OR.
    Better yet, simply use an IN clause: WHERE id IN ($id1, $id2, $id3, $id4) which is logically an OR grouped together.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for your help

    I had not used the "IN" before


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


  •  

    Posting Permissions

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