, Update mysql database data using arrays-php Tutorial

Source: Internet
Author: User
For help, I want to implement the method of updating mysql database data using arrays. The data can be changed based on the array key value and value. For example, $ arr [13] Zhang San; $ arr [14] Li Si & nbsp; implements changes to id3 and id4 data in the database based on the key value and value of the $ arr array. The key value is age and the value is the name. Ask experts for help. ------ Solution ------------------ PHPc for help, using arrays to update mysql database data
I want to implement data changes based on the array's key value and value.
Example: $ arr [13] = 'Zhang San'; $ arr [14] = 'Li si'
Modify the data of id = 3 and id = 4 in the database based on the key value and value of the $ arr array. The key value is age and the value is the name.
Ask experts for help.

------ Solution --------------------
PHP code
// Append id, deformation: $ ar = array (3 => array (13 => 'Zhang San'), 4 => array (14 => 'Li si '),); foreach ($ ar as $ id = >$ v) {list ($ name, $ aeg) = each ($ v); $ SQL = "update tbl_name set aeg = $ aeg, name = '$ name' where id = $ id "; // perform database operations}

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.