Php batch data addition and batch data update methods

Source: Internet
Author: User
If php wants to save data in batches, we only need to use the SQL insertinto statement to save data in batches. if it is to update data, updateset can be used to complete the update. The operation method is very simple, the following are two examples. batch... if php wants to save data in batches, we only need to use the SQL insert into statement to save data in batches. If update set is used to update data, the update can be completed, the operation methods are very simple. below are two examples.

Batch data input

Design method:Submit multiple form records at the same time, set the same text domain name for each record, and then read and extract the data submitted by the form through the for loop on the form processing page, finally, add the data to the database one by one in the form of data.

Use the count () function to obtain the number of elements in the array. int count (mixed var );

Form submission page. the code is as follows:

Database Connection page, the code is as follows:
 

Form processing page, the code is as follows:

  

Batch update data

The while, list (), and each () functions are used to update data in batches. the list () function is used to assign values to multiple variables at a time. the code is as follows:

   

Form processing page, the code is as follows:

    

Summary: my friends will find that the two examples have something in common. One is that the form name of the form from is in the form of a counts [] array, in php processing, the accept page will use for or while for traversal. below I will give you a simple analysis of these two examples.

Counts []: This indicates an array in the form. if you have 10 forms, our name = counts [] indicates that all of them are the same array, once you know that this is an array, you will know why traversal is used.

For or while: because the form is an array, we can traverse the array and save the data. the following code:

While (list ($ name, $ value) = each ($ _ POST) {OR

For ($ I = 0; $ I

Related Article

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.