首页 > php框架 > php 批量增加数据

php 批量增加数据

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) <2 )
  {
   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]己存在php了");
   }
   else
   {
    try{     
     $Db->query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values($array,$cityname,$orderid,$d)");
     MessAge(操作成功,addtype.php);
    }catch (Exception $e){
     MessAge(失败成功);
    }
   }
  }
   
 }

本站原创转载注明 php
 


本文地址:http://www.phprm.com/frame/php1004957.html

转载随意,但请附上文章地址:-)

标签:none

发表留言