Current location: Hot Scripts Forums » Programming Languages » PHP » delete duplicate rows in mysql using php

delete duplicate rows in mysql using php

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-12-04, 05:20 PM
seans9 seans9 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
delete duplicate rows in mysql using php

ok im not that advanced in php...but here is the deal. i have a database with a lot of email addresses (some of which are duplicates). each email address has its own row. what i want to do is go through and delete the rows with duplicate ones (leaving at least one of the email addresses)...i hope that makes sense. this is what i wrote and its not working. PLEASE help. thanks

PHP Code:
$query="SELECT * FROM `emails` ORDER BY `email` ASC LIMIT 0, 30";
mysql_query($query);
$result=mysql_query($query); 

$numrows=mysql_num_rows($result);

$totalemailsdeleted=0;
$i=1;
$i2=0;
while(
$i2 $numrows)
{
    
$id=mysql_result($result$i2id);
    
$email=mysql_result($result$i2email);
    while(
$i $numrows)
    {
        
$idcompare=mysql_result($result$iid);
        
$emailcompare=mysql_result($result$iemail);
        if(
$emailcompare == $email)
        {
            
$query="DELETE FROM `emails` WHERE `id` = '$idcompare' LIMIT 1";
            
mysql_query($query);
            
$emailsdeleted.="$emailcompare<br>";
            
$totalemailsdeleted++;
            
$numrows=mysql_num_rows($result);
        }
        else
        {
        }
        
$i++;
    }
    
$i2++;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM
Error when trying to create MySQL table via PHP HasansWeb PHP 2 01-06-04 06:13 PM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 04:31 AM
select & delete mysql queries superman PHP 2 07-20-03 04:08 AM


All times are GMT -5. The time now is 12:31 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.