mysql - Generate a random DB insert with PHP -


i have 2 tables this:

table: matrix

    matrix_id      round_id    p_1_1     p_1_2     p_2_1     p_2_2     p_3_1     p_3_2     int(11)        int(11)    int(11)   int(11)   int(11)   int(11)   int(11)   int(11)    autoincrement 

table: matrix_elements:

element_id       matrix  int(11)         int(11) autoincrement 

now need randomly select table matrix_elements , insert new row table matrix. each of p_1_1, p_1_2 etc.. have filled random matrix matrix_elements table.

the requirement each 2 of columns p_1_1 etc.. have filled value: 8

i totally lost , did not try before ask. in need of directions in order achieve this, not necessarly prepared code.

thanks suggestion.

this takes multiple statements 1 row... , may have misunderstood requirements, here goes:

edit: modified 1 statement , work rand()

insert matrix select   null,   1, -- no idea round_id should be...   if( 0 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)),   if( 1 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)),   if( 2 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)),   if( 3 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)),   if( 4 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)),   if( 5 in (one8, two8), 8, (select element_id                               matrix_elements order rand() limit 1)) (   select     one8,     if( one8 = two8, two8 + 1, two8 ) two8     (       select         floor(rand() * 6) one8,         floor(rand() * 5) two8     ) ) b; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -