SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is this possible "IF" statement

    Wondering if this is possible, or should I do an additional select query before running this?

    Code MySQL:
    DELETE FROM 
        {$this->tblName}
     
    WHERE 
        `id`='$id'
     
    IF 
        (
        `assign_user` = '{$this->userID}'
        )
     
    LIMIT 
        1

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    what are you doing? please explain

    some of us don't do php, and after all, you did post this question in the mysql forum
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, lol okay :P

    It was basically for a user permission, I popped 2 notes in here so it makes sense.

    Code MySQL:
    DELETE FROM
        notes   
     
    WHERE
        -- First, Pick the Note to Delete
        `id` = '222'
     
    IF
        (
        -- Then, Only delete the Note if the current selected Note
        -- Has this value, otherwise don't erase it
     
        `assign_user` = '13'
        )
     
       -- I only want to erase one at a time.
    LIMIT
        1

    What am I doing up at 5am lol. What is anyone doing up at 5am..

    I bought a Rubix Cube btw, that thing is impossible to solve lol.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by JREAM View Post
    It was basically for a user permission
    Here is how you would do it.

    Code MySQL:
    DELETE FROM
        notes   
    WHERE
        id = 222
        AND assign_user = 13

    You shouldn't need the LIMIT when the id's are unique.

    Quote Originally Posted by JREAM View Post
    I bought a Rubix Cube btw, that thing is impossible to solve lol.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    what puzzles me is how you would allow some user who ~isn't~ the assign_user to even get to the point in your app where they can request deletion of a note that isn't theirs

    but the AND is how you would do it
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks, I don't know why I didn't realize to use an AND statement.

    For the most part someone can't get to that section, but just to be double secure I want the query safe too. It's a lot of working writing an application, I don't think I realized what i was getting into :P

    haha


Bookmarks

Posting Permissions

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