How to write more than half of php Group combinations to the database

Source: Internet
Author: User
Php multi-array combination writing method this post was last edited by wjm_hi from 2013-10-2515: 55: 24. I made a score Management System discipline $ xk & nbsp; array (); grade $ nj & nbsp; array (); class $ bj & nbsp; array (); there are three arrays, how to write php multi-array combinations to the database

This post was last edited by wjm_hi at 15:55:24

I made a score management system.

// Subject
$ Xk = array ();

// Grade
$ Nj = array ();

// Class
$ Bj = array ();

There are three arrays, which are generated based on the formula * grade * class, and then written to the database.
For example:
When count ($ xk) is 2, two subjects are selected.
When count ($ nj) is 3, three grades are selected.
When count ($ bj) is 7, it indicates that 7 grades are selected.
2*3*7 data records should be inserted into the database. how can this problem be achieved?

Share:


------ 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.