Home >Backend Development >PHP Tutorial >Add data in batches with php_PHP tutorial
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
www.bkjia.com
http: //www.bkjia.com/PHPjc/445023.html