《PHP學(xué)習(xí):PHP查詢并刪除數(shù)據(jù)庫多列重復(fù)數(shù)據(jù)的方法(利用數(shù)組函數(shù)實現(xiàn))》要點:
本文介紹了PHP學(xué)習(xí):PHP查詢并刪除數(shù)據(jù)庫多列重復(fù)數(shù)據(jù)的方法(利用數(shù)組函數(shù)實現(xiàn)),希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP應(yīng)用本文實例講述了PHP查詢并刪除數(shù)據(jù)庫多列重復(fù)數(shù)據(jù)的辦法.分享給大家供大家參考,具體如下:
PHP應(yīng)用
<?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應(yīng)用更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
PHP應(yīng)用希望本文所述對大家PHP程序設(shè)計有所贊助.
《PHP學(xué)習(xí):PHP查詢并刪除數(shù)據(jù)庫多列重復(fù)數(shù)據(jù)的方法(利用數(shù)組函數(shù)實現(xiàn))》是否對您有啟發(fā),歡迎查看更多與《PHP學(xué)習(xí):PHP查詢并刪除數(shù)據(jù)庫多列重復(fù)數(shù)據(jù)的方法(利用數(shù)組函數(shù)實現(xiàn))》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/7520.html