[How do I write four arrays to the database at the same time ?]

Source: Internet
Author: User
[How to write four arrays to the database at the same time ?] $ _ POST [a] & nbsp; value: 1, 2, 4, 4, 5 $ _ POST [B] & nbsp; the value is a, B, c, d, e $ _ POST [c] & nbsp; & nbs [how to write four arrays to the database at the same time?]
$ _ POST ['A'] value: 1, 2, 3, 4, 5
$ _ POST ['B'] value: a, B, c, d, e
$ _ POST ['c'] values: male, female, female, male, and male
$ _ POST ['D'] values: 25, 26, 27, 26


The four arrays are . Now I want to write them all into the database. how should I write the loop?

The last format written to the database should be
No. name gender age
Article 1: 1 a male 25
Article 2: 2 B female 26
Article 3: 3 c women 27
Article 4: 4 d male 26
Article 5: 5 e male 26
------ Solution --------------------

$ _ POST ['A'] = '1, 2, 3, 4, 5 ';
$ _ POST ['B'] = "a, B, c, d, e ";
$ _ POST ['c'] = "male, female, female, male ";
$ _ POST ['D'] = "25, 26, 27, 26 ";

$ A = explode (',', $ _ POST ['A']);
$ B = explode (',', $ _ POST ['B']);
$ C = explode (',', $ _ POST ['c']);
$ D = explode (',', $ _ POST ['D']);


Foreach ($ a as $ key => $ value ){
$ SQL = "inser into tbl_name values ('$ value',' {$ B [$ key]} ',' {$ c [$ key]} ', '{$ d [$ key]}'); ";
// Mysql_query ($ SQL );
Echo $ SQL, PHP_EOL;

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.