php 批量增加資料

來源:互聯網
上載者:User

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]己存在資料庫了");
   }
   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.net
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.