deleting entry

Discussion in 'Databases' started by deemainer, Mar 6, 2009.

  1. #1
    Hi all,

    How would i delete entrys after a search? Say for instance i have this...

    $sql = 'SELECT * FROM `table_name` WHERE `TITLE` LIKE \'%tramadol%\' OR
    `DESCRIPTION` LIKE \'%tramadol%\''
    . ' OR `TITLE` LIKE \'%viagra%\''
    . ' OR `DESCRIPTION` LIKE \'%viagra%\''
    . ' LIMIT 0 , 30';

    which seems to work fine as a search for spam terms. What would i need to add to then delete those entries?

    Thanks
     
    deemainer, Mar 6, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    What are you doing with the SELECT results? Are you putting them in an array or collection? If so, iterate through the list and DELETE FROM [table_name] WHERE [record_id] = [id in the list]. I hope that makes sense. I do not know your specific requirements, so let me know if you need another option.
     
    Social.Network, Mar 6, 2009 IP
  3. Sake7

    Sake7 Well-Known Member

    Messages:
    1,098
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    110
    #3
    DELETE FROM table_name
    WHERE condition

    or if you are in myphpadmin, you can check all results and delete them with 2 clicks, after you run your script.
     
    Sake7, Mar 6, 2009 IP
  4. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #4
    sorry...i should have been more specific.

    I have a directory that gets a lot of entrys and a lot of of spam.Its a pain to go through the admin panel so ive been experimenting doing it in php admin (im new to sql but need it for another project also so learning) As mentioned you can do it in a couple clicks but id like to just call a file from a browser with a list of spam words , check it then delete all. So ideally... call a file of "banned" words, display links(although not strictly neccasary) then delete them from table.

    So i guess my question should be how do i iterate a query, display it and decide to select all and delete?

    thanks
     
    deemainer, Mar 6, 2009 IP