Ask PHP more than half of the group composition to write to the database method

Source: Internet
Author: User
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]. "')";
}
  • 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.