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
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号