Home  >  Article  >  Backend Development  >  PHP method to query and delete duplicate data in multiple columns of database (implemented using array functions), multi-column array_PHP tutorial

PHP method to query and delete duplicate data in multiple columns of database (implemented using array functions), multi-column array_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:58:44823browse

How to query and delete duplicate data in multiple columns of the database with PHP (implemented using array functions), multi-column array

This article describes how to query and delete duplicate data in multiple columns of the database with PHP method. Share it with everyone for your reference, the details are as follows:

<&#63;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);
&#63;>

Readers who are interested in more PHP related content can check out the special topics of this site: "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php mysql database operation introductory tutorial" Summary of common database operation skills in PHP》

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • How to query mysql database in php and save the results to an array
  • thinkphp data query and array traversal examples
  • ThinkPHP query returns a simple field array method
  • php implements multi-condition query implementation method through array (string splitting)
  • php quickly queries its parent key and parent key based on the key name in a multi-dimensional array Value code
  • php array operations (add, delete, query, sort) and other function descriptions
  • php method of randomly splitting strings into arrays of different lengths
  • php delete Methods for repeating elements in arrays
  • PHP methods for counting the number of array elements
  • PHP methods for querying different elements in two arrays

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1102465.htmlTechArticleHow to query and delete duplicate data in multiple columns of the database using PHP (implemented using array functions), multi-column arrays are described in this article with examples How to query and delete duplicate data in multiple columns of database using PHP. Share to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn