$_post[' A '] value is 1,2,3,4,5
$_post[' B '] value is a,b,c,d,e
$_post[' C ' value is male, female, female, male, male
$_post[' d '] value is 25,26,27,26,26
These four arrays are also In the back. Now I'm going to write them all into the database, how should the loops be written?
The last write to the database format should be
Number name Gender age
Article I: 1 a male 25
Article two: 2 B female 26
Article three: 3 C female 27
Fourth: 4 D male 26
Fifth article: 5 e male 26
Reply to discussion (solution)
$_post[' a '] = array (1,2,3,4,5); $_post[' B '] = array (' A ', ' B ', ' C ', ' d ', ' e '); $_post[' C '] = array (' Male ', ' female ', ' female ', ' male ', ' male '); $_ post[' d '] = Array (25,26,27,26,26), foreach ($_post[' a '] as $i = = $v) { $sql = "Inser into tbl_name values (' $v ', ' {$_po st[' B ' [$i]} ', ' {$_post[' C ' [$i]} ', ' {$_post[' d ' [$i]} ') "; Echo $sql, Php_eol;}
Inser into tbl_name values (' 1 ', ' a ', ' Male ', ' 25 ')
Inser into tbl_name values (' 2 ', ' B ', ' Female ', ' 26 ')
Inser into tbl_name values (' 3 ', ' C ', ' Female ', ' 27 ')
Inser into tbl_name values (' 4 ', ' d ', ' Male ', ' 26 ')
Inser into tbl_name values (' 5 ', ' e ', ' Male ', ' 26 ')
$_post[' a '] = ' 1,2,3,4,5 '; $_post[' B '] = "a,b,c,d,e"; $_post[' C '] = "male, female, female, male, male"; $_post[' d '] = "25,26,27,26,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;