Request PHP Majority Group composition write database method

Source: Internet
Author: User
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?


Reply to discussion (solution)

PHP multi-loop, and then the data subscript loop finally written to the database, PHP base Poor, request the heroes to help

$xk =array ("1", "2");
$nj =array ("1", "2", "3");
$BJ =array ("1", "2", "3", "4", "5", "6", "7");
$xk =count ($XK);
$nj =count ($NJ);
$BJ =count ($BJ);
$test = "$xk * $NJ * $BJ";
Echo $test;
Exit
?>

Dizzy, understand wrong. 、

How do you understand that?

$xk =array ("1", "2");
$nj =array ("1", "2", "3");
$BJ =array ("1", "2", "3", "4", "5", "6", "7");
$xk =count ($XK);
$nj =count ($NJ);
$BJ =count ($BJ);
$test = "$xk * $NJ * $BJ";
Echo $test;
Exit
?>

I'm going to build the INSERT INTO statement.


Insert INTO ' examinfo ' (' NJ ', ' bj ', ' xk ') VALUES ($nj, $BJ, $xk), values are inserted after $xk* $nj * $BJ so many, how to do it?

Find the code for calculating Cartesian product in the essence area

Write a stupid method.
$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) {
Inserting data
}

This is so complicated, can you do it with for?

for ($i =0; $i < p="">

$xk =array ("1", "2"), $nj =array ("1", "2", "3"), $BJ =array ("1", "2", "3", "4", "5", "6", "7"), $arr = Array (); for ($i =0; $i
  
  

Write a stupid method.
$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) {
Inserting data
}

This seems to work, and in foreach, insert the data, how do you write the SQL statement?

$xk =array ("1", "2"), $nj =array ("1", "2", "3"), $BJ =array ("1", "2", "3", "4", "5", "6", "7"), $arr = Array (); for ($i =0; $i
     
    


Can I insert the data and echo the call method?

$xk =array ("1", "2"), $nj =array ("1", "2", "3"), $BJ =array ("1", "2", "3", "4", "5", "6", "7"), $arr = Array (); for ($i =0; $i
       
      

What I want is this effect, I'm going to put insert INTO ' examinfo ' (' NJ ', ' bj ', ' XK ') VALUES ($nj, $BJ, $XK) to//Where to insert the data, how do I write it.

$xk =array ("1", "2"), $nj =array ("1", "2", "3"), $BJ =array ("1", "2", "3", "4", "5", "6", "7"), $arr = Array (); for ($i =0; $i
        
        

 $xk =array ("1", "2"), $nj =array ("1", "2", "3"), $BJ =array ("1", "2", "3", "4", "5", "6", "7 $arr = Array (); for ($i =0; $i 
           
           


Thank you very much, but this SQL statement can do some optimizations best, INSERT into ' examinfo ' (' NJ ', ' bj ', ' XK ') VALUES ($nj, $BJ, $XK) has been this sentence In the loop, if insert INTO ' examinfo ' (' NJ ', ' bj ', ' XK ') VALUES (1, 1, 1), (1, 1, 2), (1, 1, 3) Such SQL statements are perfect.

Halo. Man, you want to realize how not to think about yourself. Can not expect others to do everything you do well, others can only give you ideas ah.

Halo. Man, you want to realize how not to think about yourself. Can not expect others to do everything you do well, others can only give you ideas ah.


Well, there is this idea, I can continue to do, thank you, optimization of the matter I have ideas, thank you

  • Related Article

    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.