PHP查詢并刪除數(shù)據(jù)庫多列重復數(shù)據(jù)的方法(利用數(shù)組函數(shù)實現(xiàn))
更新時間:2016年02月23日 09:36:17 作者:xxzqyall
這篇文章主要介紹了PHP查詢并刪除數(shù)據(jù)庫多列重復數(shù)據(jù)的方法,利用數(shù)組函數(shù)實現(xiàn)該功能,涉及PHP數(shù)據(jù)庫操作的相關技巧,需要的朋友可以參考下
本文實例講述了PHP查詢并刪除數(shù)據(jù)庫多列重復數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:
<?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數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
POSIX 風格和兼容 Perl 風格兩種正則表達式主要函數(shù)的類比(preg_match, preg_replace,
POSIX 風格和兼容 Perl 風格兩種正則表達式主要函數(shù)的類比(preg_match, preg_replace, ereg, ereg_replace) ,需要的朋友可以參考下。2010-10-10
ubuntu下編譯安裝xcache for php5.3 的具體操作步驟
本篇文章是對ubuntu下編譯安裝xcache for php5.3的操作進行了詳細的分析介紹,需要的朋友參考下2013-06-06
攻克CakePHP系列一 連接MySQL數(shù)據(jù)庫
請先參閱以前寫的文章以便對CakePHP有所了解文章,上一篇2008-10-10

