PHP queries and deletes multiple duplicate data columns in the database (implemented using array functions) and Multi-column Arrays

Source: Internet
Author: User

PHP queries and deletes multiple duplicate data columns in the database (implemented using array functions) and Multi-column Arrays

This example describes how to query and delete multiple duplicate data columns in a database using PHP. We will share this with you for your reference. The details are 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); // display the echo count ($ arr_data) before and after ). "-". count ($ arr_unique); foreach ($ arr_rep as $ key => $ value) {$ SQL _del = "DELETE F ROM friend WHERE id = '{$ key}' "; $ result = mysql_query ($ SQL _del, $ con) ;}// some codes mysql_close ($ con);?>

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.