Jump to content

Recommended Posts

I have a form that pulls feeds from a site, and inserts them into the database

<?php
$xml=("http://www.novafantasysports.com/xml/bbfpbasketballplayernews/node_feed/?User=bbfreepicks_nbaplayernews&pw=bbfpFFBP");

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('article');

$sql = "INSERT INTO feeds_history(title, author, content, date_posted) VALUES";

for ($i=0; $i<=19; $i++)
  {
  $item_title=$x->item($i)->getElementsByTagName('title')
  ->item(0)->childNodes->item(0)->nodeValue;
  
   $item_author=$x->item($i)->getElementsByTagName('author')
  ->item(0)->childNodes->item(0)->nodeValue;
  
  $item_created=$x->item($i)->getElementsByTagName('created')
  ->item(0)->childNodes->item(0)->nodeValue;
  
  $item_desc=$x->item($i)->getElementsByTagName('content')
  ->item(0)->childNodes->item(0)->nodeValue;
$sql .= "('" . mysql_real_escape_string($item_title). "', '". mysql_real_escape_string($item_author) . "', '". strip_tags(mysql_real_escape_string($item_desc)) . "', '". mysql_real_escape_string($item_created) . "')"; 

  //echo ("<a href='" . $item_link  . "'>" . $item_title . "</a>");
  //echo ($item_desc);
  
if($i < 19) {
$sql .= ", ";
}
else {
$sql .=";";
}
  }
$result = mysql_query($sql); 
?>

 

Now I need to check it there are any duplicates, and then delete only the duplicates, except one from the database.

 

So, if there are 3 of the title "Try This", I need to delete 2 of those rows.

 

How would I go about doing this?

Link to comment
https://forums.phpfreaks.com/topic/170268-duplicate-rows/
Share on other sites

First off you could add a unique key to the table so they don't get in there in the first place.

 

As far as deleting them, you can do it without the temp table if your existing table has a column that is different for every row, such as a primary key.

 

Does your table have such a column?

Link to comment
https://forums.phpfreaks.com/topic/170268-duplicate-rows/#findComment-898371
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.