PHP Query and delete database multiple-column duplicate data method (implemented by Array function) _php techniques

Source: Internet
Author: User

This article describes a PHP query and deletes a database of multiple-column duplicate data methods. Share to everyone for your reference, specific 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);
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);
Displays the amount of
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);
? >

For more information about PHP interested readers can view the site topics: "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP Common database Operation tips Summary"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.