Sun Oct 26, 2008 6:19 pm
<?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|
----------
*/
$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
Thu Jan 19, 2012 9:49 am
Fri Jan 20, 2012 11:23 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.