Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

delete duplicate rows in mysql using php

Sun Oct 26, 2008 6:19 pm

Code:
<?php

/* Removes duplicate records in a table

Code by:
Bardhyl Fejzullahi
[email protected]
17.09.2008
Pristina, Kosovo

EX.
|id|name|
==========
|1|test|
----------
|2|php|
----------
|3|test|
----------
Result
|id|name|
==========
|1|test|
----------
|2|php|
----------
*/


$cnmysql_connect("localhost""root""") or die('Could not connect');
$dbmysql_select_db(test$cn) or die('Could not select database');


    
$query="SELECT * FROM name"
       
    
$result=mysql_query($query);
    echo 
mysql_error();


        while(
$row mysql_fetch_array($resultMYSQL_BOTH))
       
        {
                
$query1="SELECT * FROM tablename WHERE name = '".$row[1]."'"
       
                
$result1=mysql_query($query1);
                
$count mysql_num_rows($result1) - 1;
               
                
mysql_query("DELETE FROM tablename WHERE name='".$row[1]."' LIMIT $count");
                echo 
"deleted $row[1] <br>";
           
}
        echo 
mysql_error();
    
?>
       

-- 
Bardhi




Re: delete duplicate rows in mysql using php

Thu Jan 19, 2012 9:49 am

hi plz define $link variable.

Re: delete duplicate rows in mysql using php

Fri Jan 20, 2012 11:23 pm

it is a bug , i deleted it.

Post a reply
  Related Posts  to : delete duplicate rows in mysql using php
 three rows frameset .     -  
 Select odd rows from table     -  
 Get affected rows for an update in php     -  
 Listing All Rows and Fields in a Table     -  
 Number of Rows Returned by query in php     -  
 different colors for table Even- Odd rows and Cells     -  
 Multi colored table rows     -  
 Randomly generated rows and columns in Array     -  
 Uneven rows-2-dimenstionals-triangle look like 2D array     -  
 Delete a file in php     -  

Topic Tags

PHP Database