MySQL syntax question

Discussion in 'PHP' started by rwin2007, Nov 28, 2009.

  1. #1
    I am looking to delete all comments from my wordpress install that contain "HTTP://" within the comment content.

    I am using this syntax but it keeps on receiving syntax error


    Any help on this?

    Thanks in advance
     
    rwin2007, Nov 28, 2009 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    LIKE 'http://%'
    
    Code (markup):
     
    nico_swd, Nov 28, 2009 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you're deleting, you'll want to use DELETE instead of SELECT
    Something like this should do it
    DELETE FROM `wp_comments`
    WHERE ((`wp_comments`.`comment_approved` = "0") AND (`wp_comments`.`comment_content` LIKE "%http://%")) 
    Code (markup):
     
    JAY6390, Nov 28, 2009 IP
  4. rwin2007

    rwin2007 Well-Known Member

    Messages:
    1,231
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
    #4
    thanks mate! Looked over that one. It worked.
     
    rwin2007, Nov 28, 2009 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No probs :)
     
    JAY6390, Nov 28, 2009 IP
  6. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    wth is that - shouldn't it be

    LIKE '%http://%'
    PHP:
    :confused:

    ...or is the % a wildcard for a regex match?
     
    szalinski, Nov 30, 2009 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    It's a wildcard. It means it should begin with http, but can end with whatever.

    It's not regex, though.
     
    nico_swd, Dec 2, 2009 IP
  8. kingsoflegend

    kingsoflegend Well-Known Member

    Messages:
    202
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #8
    Yes, it should be %http://%. You're looking for posts that contain that text and don't just start with it.
     
    kingsoflegend, Dec 2, 2009 IP
  9. akhil1311

    akhil1311 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Use this instead of "LIKE http://"
     
    akhil1311, Dec 2, 2009 IP
  10. sloddl

    sloddl Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    #1 use DELETE FROM and not SELECT FROM
    #2
    LIKE '%http://%'
    Code (markup):
     
    sloddl, Dec 3, 2009 IP