search
Homephp教程php手册PHP查询并删除数据库多列重复数据的方法(利用数组函数实现),多列数组

PHP查询并删除数据库多列重复数据的方法(利用数组函数实现),多列数组

本文实例讲述了PHP查询并删除数据库多列重复数据的方法。分享给大家供大家参考,具体如下:

<&#63;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);
//显示前后量
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);
}
// 一些代码
mysql_close($con);
&#63;>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • php查询mysql数据库并将结果保存到数组的方法
  • thinkphp数据查询和遍历数组实例
  • ThinkPHP查询返回简单字段数组的方法
  • php通过数组实现多条件查询实现方法(字符串分割)
  • php在多维数组中根据键名快速查询其父键以及父键值的代码
  • php 数组操作(增加,删除,查询,排序)等函数说明
  • php将字符串随机分割成不同长度数组的方法
  • php删除数组中重复元素的方法
  • php统计数组元素个数的方法
  • PHP实现查询两个数组中不同元素的方法
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)