本文实例讲述了php查询并删除数据库多列重复数据的方法。分享给大家供大家参考,具体如下:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db", $con);
if (!$db_selected)
{
die ("can/'t use test_db : " . mysql_error());
}
$sql = "select * from friend";
$result=mysql_query($sql,$con);
while($myrow=mysql_fetch_row($result))
{
$arr_data[$myrow[0]]=$myrow[1]."-".$myrow[2];
}
$arr_unique=array_unique($arr_data);
$arr_rep=array_diff_assoc($arr_data,$arr_unique);
//显示前后量
echo count($arr_data)."-".count($arr_unique);
foreach($arr_rep as $key=>$value){
$sql_del = "delete from friend where id = '{$key}' ";
$result=mysql_query($sql_del,$con);
}
// 一些代码
mysql_close($con);
?>
更多关于php相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!