Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 4:57 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 3 posts ] 
Author Article
 Article subject: delete duplicate rows in mysql using php
PostPosted: Sun Oct 26, 2008 6:19 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Code:
<?php

/* Removes duplicate records in a table

Code by:
Bardhyl Fejzullahi
bardh7@gmail.com
17.09.2008
Pristina, Kosovo

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


$cn= mysql_connect("localhost", "root", "") or die('Could not connect');
$db= mysql_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($result, MYSQL_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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Article subject: Re: delete duplicate rows in mysql using php
PostPosted: Thu Jan 19, 2012 9:49 am 
hi plz define $link variable.


TOP
  
Reply with quote  
 Article subject: Re: delete duplicate rows in mysql using php
PostPosted: Fri Jan 20, 2012 11:23 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
it is a bug , i deleted it.

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 3 posts ] 
Quick reply


  

 Similar topics
 Multi colored table rows
 three rows frameset .
 How to delete/remove images from excel 2007 using POI.
 Cannot Delete Computer group
 Delete file
 How can I delete inactive friends?
 Asp.net inset update delete
 Create auto numbered column in mysql query
 Delete using native query
 DYNAMIC DATES IN MYSQL

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Article | Next Article 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team