Php batch add data _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php adds data in batches. Below we will test the code for adding cities in php in batches to add data in batches. FunctionAddtype () {if ($ _ FILES) {exit;} $ info; $ citynametrim (PostGet (city php batch add data
Next we will test a php code to add cities in batches and separate them with "|.
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 ('select a city ');
}
Elseif (strlen ($ citytype) <2)
{
MessAge ('input City Region ');
}
Elseif (! Is_numeric ($ orderid ))
{
MessAge ('sorry, the order must be a number! ');
}

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! ');
}
}
}
MessAge ("added successfully, failed $ info", 'addtype. php ');
}
Else
{
$ 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 has a database ");
}
Else
{
Try {
$ Db-> query ("Insert into 111cn_city (cntitle, upid, orderid, createdate) values ('$ array', $ cityname,' $ orderid', '$ d ') ");
MessAge ('Operation succeeded ', 'addtype. php ');
} Catch (Exception $ e ){
MessAge ('failed successfully ');
}
}
}

}

Original site reprinted with www.111cn.cn


Http://www.bkjia.com/PHPjc/445023.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445023.htmlTechArticlephp batch increase data below we are testing a php batch increase city code to | separate Oh. Function Addtype () {if ($ _ FILES) {exit;} $ info = ''; $ cityname = trim (PostGet ('City...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.