From the data entered by the user, an array is created, and in the database table each element must be written in the same column but in a new row, for example:

$array_m = (1, 5, 3, 8, 125, 6); 

It is necessary to create 6 lines where the next element will be written in the column of each line num.

  • @ shumik-ua And what is the structure of the database? - Ilya Yaremchuk
  • @IlyaYaremchuk two columns, one must fill with the name num - shumik_UA

1 answer 1

You can do this with array brute force:

 foreach($array_m as $value){ mysql_query('INSERT INTO table (num) VALUES ('.$value.')'); } 
  • did it like this, but .. echo $ value displays everything as it should, but an empty table is created in the database ... $ i = 1; $ array_m = array (); while ($ i <= $ num_of_members) {$ array_m [$ i] = $ i; $ i ++; } foreach ($ array_m as $ value) {echo $ value; $ mysqli -> query ('INSERT INTO mybase . lottery_$num ( num ) VALUES ($ value)'); } - shumik_UA
  • @ shumik-ua table empty is created? or entry in the table? Write more code! - Ilya Yaremchuk
  • oops .. changed the parentheses in query (',,,') to query ("...") the table is not empty, but displays only one line with num '1' - shumik_UA
  • @ shumik-ua show all your code by adding entries - Ilya Yaremchuk