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);?>