PHP Query and delete database multi-column duplicate data method (using Array function Implementation), multi-column Array _php tutorial

Source: Internet
Author: User

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 ...

  • 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.