Request PHP Majority Group composition write database method
This post was last edited by Wjm_hi on 2013-10-25 15:55:24
I do a grade management system
Subject
$XK = Array ();
Grade
$nj = Array ();
Class
$BJ = Array ();
There are three arrays, according to the discipline * grade * class This formula to generate how many data, and then write to the database.
For example:
When Count ($XK) is 2, it indicates that 2 disciplines have been selected
When Count ($NJ) is 3, the description selects 3 grades
When Count ($BJ) is 7, the description selects 7 grades
This should be inserted into the database 2*3*7 data, how can this be done?
Share to:
------Solution--------------------
$xk =array ("1", "2");
$nj =array ("1", "2", "3");
$BJ =array ("1", "2", "3", "4", "5", "6", "7");
$arr = Array ();
for ($i =0; $i
<>
for ($j =0; $j
<>
for ($k =0; $k
<>
$arr [] = Array ($xk [$i], $nj [$j], $BJ [$k]);
}
}
}
foreach ($arr as $row) {
$sql = "INSERT into ' examinfo ' (' NJ ', ' bj ', ' XK ') VALUES ('". $row [0]. "', '". $row [1]. "', '". $row [2]. "')";
}