PHP Query and delete database multi-column duplicate data method (using Array function Implementation), multi-column array
This article explains how PHP queries and removes multiple columns of data from a database. Share to everyone for your reference, as follows:
<?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) and 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);//display front and rear volume 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);} Some code mysql_close ($con);? >
More readers interested in PHP related content can view the topic: "PHP Primer for Object-oriented programming", "PHP String Usage Summary", "Php+mysql Database Operations Primer" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- PHP query MySQL database and save the results to an array of methods
- thinkphp data querying and iterating over an array instance
- thinkphp query returns a simple field array method
- PHP implementation of multi-conditional query by array (string segmentation)
- PHP quickly queries the code of its parent key and parent key value in a multidimensional array based on the key name
- PHP array Operations (ADD, delete, query, sort) function description
- PHP methods for randomly dividing strings into arrays of different lengths
- How PHP deletes repeating elements in an array
- How to count the number of elements in a PHP array
- PHP implements a method for querying different elements in two arrays
http://www.bkjia.com/PHPjc/1102465.html www.bkjia.com true http://www.bkjia.com/PHPjc/1102465.html techarticle PHP Query and delete database multi-column duplicate data method (using Array function Implementation), multi-column array in this paper, we describe PHP query and delete the database multi-column duplicate data method. Share to ...