1

Possible Duplicate:
How to delete duplicate rows from a MySQL table

I have been looking all across the Internet for a decent answer but I still don't understand how to delete duplicate rows. I have a query below and can someone please show me how to correctly implement the ability to delete duplicate rows?

Any ideas?

$bbc_values = array('http://www.bbc.co.uk/news/health-', 
    'http://www.bbc.co.uk/news/politics-', 
    'http://www.bbc.co.uk/news/uk-', 
    'http://www.bbc.co.uk/news/technology-', 
    'http://www.bbc.co.uk/news/world-', 
    'http://www.bbc.co.uk/news/england-', 
    'http://www.bbc.co.uk/news/northern_ireland-', 
    'http://www.bbc.co.uk/news/scotland-', 
    'http://www.bbc.co.uk/news/wales-', 
    'http://www.bbc.co.uk/news/business-',
    'http://www.bbc.co.uk/news/education-',
    'http://www.bbc.co.uk/news/science_and_enviroment-',
    'http://www.bbc.co.uk/news/entertainment_and_arts-');


// BBC Algorithm
foreach ($links as $link) {
    $output = array(
        "title"       => Titles($link), //dont know what Titles is, variable or string?
        "description" => getMetas($link),
        "keywords" => getKeywords($link),
        "link"        => $link
    );
    if (empty($output["description"])) {
        $output["description"] = getWord($link);
    }
    $data = '"' . implode('" , "', $output) . '"';

    if (substr_in_array($output, $bbc_values)) {
        $result = mysql_query("INSERT INTO news_story (`title`, `description`, `keywords`, `link`)    VALUES (" . $data . ")");
        $delete = mysql_query("DELETE FROM news_story WHERE link='{$output['link']}'");

    }
    if (!substr_in_array($output, $bbc_values)) {
        echo "Does not equal data";
    }
Community
  • 1
  • 1
  • 4
    nice [sql injection vulnerabilities](http://bobby-tables.com)... hope you enjoy having your server pwn3d. – Marc B Dec 18 '12 at 15:32
  • Your question isn't complete - where does `$links` come from ? and what are you trying to achieve ? – Manse Dec 18 '12 at 15:33
  • 1
    What does this has to do with the `INSERt` statement? Do you want to check if the INSERted values is duplicate or not? If so you can create a unique key then do `INSERT .. ON DUPLICATE KEY UPDATE` – Mahmoud Gamal Dec 18 '12 at 15:34
  • 2
    @MarcB How is this open to sql injection ? there is no user input here – Manse Dec 18 '12 at 15:35
  • 1
    SQL injection isn't an issue of user input, but of building SQL with untrusted data, regardless of the source. – Andy Lester Dec 18 '12 at 15:36
  • 3
    If you search this site for your *exact question title*, you get tons of examples of how to delete duplicate records from a table. How is what you need different from those examples? – dan1111 Dec 18 '12 at 15:36

0 Answers0