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

php 批量增加数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:22:37851browse

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
 


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
Previous article:php图片上传类Next article:php google 风格分页代码