Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何过滤Excel中的重复数字以将数据发送到MySQL,我想用Php显示警报消息?_Php_Mysql_Excel - Fatal编程技术网

如何过滤Excel中的重复数字以将数据发送到MySQL,我想用Php显示警报消息?

如何过滤Excel中的重复数字以将数据发送到MySQL,我想用Php显示警报消息?,php,mysql,excel,Php,Mysql,Excel,我尝试的代码只用于将excel数据导出到MySql数据库 $source = fopen('email.csv', "r"); $query = ''; while (($data = fgetcsv($source, 1000)) !== FALSE) { for ($i = 1; $i < 2; $i++) { $name[$i] =

我尝试的代码只用于将excel数据导出到MySql数据库

$source = fopen('email.csv', "r");
                $query = '';
                while (($data = fgetcsv($source, 1000)) !== FALSE) {
                    for ($i = 1; $i < 2; $i++) {
                        $name[$i] = $data[0];
                        $email[$i] = $data[1];
                        $mobile[$i] = $data[2];


                        $query.="INSERT INTO table tablename (`name1`,`email`, mobile) VALUES ('" . $name[$i] . "','" . $email[$i] . "','" . $mobile[$i] . "') ;";
                        //return $query;
                    }
                }
                $connection->createCommand($query)->execute();
我想过滤重复的数字,并显示过滤数字的警报消息。。。可能吗

是的,可能: 请尝试此代码仅插入唯一的数据

$source = fopen('email.csv', "r");
$query = '';

while (($data = fgetcsv($source, 1000)) !== FALSE) {

    $duplicate_raw = false;

    $name = $data[0];
    $email = $data[1];
    $mobile = $data[2];

    if( in_array($name , $name_array[] ){
        echo 'Alredy exists: ' . $name . '<br>';}
        $duplicate_raw = true;
    else{
        $name_array[]   = $name;}

    if( in_array($mobile , $mobile_array[] ){
        echo 'Alredy exists: ' . $mobile . '<br>';}
        $duplicate_raw = true;
    else{
        $mobile_array[]   = $mobile;}

    if( in_array($email , $email_array[]  ){
        echo 'Alredy exists: ' . $email . '<br>';}
        $duplicate_raw = true;
    else{
        $email_array[]   = $email;}


    if ($duplicate_raw == false){
        $query.="INSERT INTO table tablename (`name1`,`email`, mobile) VALUES ('" . $name . "','" . $email . "','" . $mobile . "') ;";}//return $query;

}
$connection->createCommand($query)->execute();