Home > php教程 > php手册 > php 批量增加数据

php 批量增加数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:22:37
Original
848 people have browsed it

php 批量增加数据
下面我们是测试一个php批量增加城市的代码以"|"分开哦。
function Addtype()
 {
  if( $_FILES ){exit;}
  $info ='';
  $cityname = trim(PostGet('cityname',1));
  $citytype = trim(PostGet('citytype',1));
  $orderid = trim(PostGet('orderid',1));
  
  if( $cityname ==0 || !is_numeric( $cityname ) )
  {
   MessAge('请选择城市');
  }
  elseif(strlen($citytype)   {
   MessAge('输入城市地区'); 
  }
  elseif( !is_numeric($orderid ))
  {
   MessAge('对不起,排序必须是数字哦!');
  }
  
  if( strpos($citytype,'|')!=false)
  {
   $array = explode('|',$citytype);
   if( is_array( $array ) )
   {
    $array = array_filter($array,'filter');    
   }
  }
  else
  {
   $array = $citytype;
  }
  $Db= new Db();
  $d =date("Y-m-d");
  if( is_array( $array ) )
  {
   foreach( $array as $v => $_v )
   {
    $row = $Db->query("Select * from 111cn_city where upid=$cityname and cntitle="".$_v.""");
    if( $Db->rows( $row ) )
    {
     $info.=$_v.',';
    }
    else
    {
     try{
      $Db->query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values('$_v',$cityname,'$orderid','$d')");
      
     }catch (Exception $e){
      MessAge('操作失败!');
     }      
    }    
   }
   MessAge("增加成功,失败有$info",'addtype.php');
  }
  else
  {
   $Query = $Db->query("select * from 111cn_city where upid=$cityname and cntitle="$array"");
   if( $Db->rows( $Query ) )
   {
    MessAge("对不起,你所要增加的城市[$array]己存在数据库了");
   }
   else
   {
    try{     
     $Db->query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values('$array',$cityname,'$orderid','$d')");
     MessAge('操作成功','addtype.php');
    }catch (Exception $e){
     MessAge('失败成功');
    }
   }
  }
   
 }

本站原创转载注明 www.111cn.cn
 


source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template