So, I have problem with adding columns to table tablica, tablica has only id column and trough loop I am adding column names with ALTER query and then I am adding values from table prva with query INSERT, here's my code:
if(isset($_POST['submit']))
{
mysql_query("CREATE TABLE tablica (id INT PRIMARY KEY AUTO_INCREMENT)");
if(isset($_POST['kolona']))
{
foreach($_POST['kolona'] as $vrednost)
{
mysql_query("ALTER TABLE tablica ADD $vrednost text");
mysql_query("INSERT INTO tablica ($vrednost) SELECT $vrednost FROM prva");}
}
}
I have problem in what way columns are added, first column is ok, then the second one begins where the first ends, so my ouput is something like this:
id column1 column2
1 a1 NULL
2 a2 NULL
5 NULL b1
6 NULL b2
and it needs to be:
id column1 column2
1 a1 b1
2 a2 b2
so I need to put the column2 in the place, than and id's will be sorted also i think. Can anyone help? Tnx