Home >Backend Development >PHP Tutorial >Add data in batches with php_PHP tutorial

Add data in batches with php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:06:391059browse

PHP adds data in batches
Below we are testing a PHP code to batch add cities, separated by "|".
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('Please select a city');
}
elseif(strlen($citytype) <2 )
{
MessAge ('Enter city area');
}
elseif( !is_numeric($orderid ))
{
MessAge('Sorry, the order must be numeric!');
}

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('Operation failed! ');
                                                                         🎜> $Query = $Db->query("select * from 111cn_city where upid=$cityname and cntitle="$array"");
if( $Db->rows( $Query ) )
{
MessAge("Sorry, the city [$array] you want to add already exists in the database");
}
else
{
try{
$Db-> ;query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values('$array',$cityname,'$orderid','$d')");
MessAge('Operation successful',' addtype.php');
}catch (Exception $e){
MessAge('Failed successfully');
}
}
}

}

Original reprints on this site are marked www.111cn.cn





http://www.bkjia.com/PHPjc/445023.html


www.bkjia.com


true

http: //www.bkjia.com/PHPjc/445023.html

php Batch Add Data Below we are testing a php code to batch add cities separated by |. function Addtype() { if( $_FILES ){exit;} $info =''; $cityname = trim(PostGet('city...
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