PHP - Gernerate Multiple columns in PHP - Asked By sathish on 25-Jun-12 03:16 AM

Dear Team..

I Don't know how to generate multiple columns in php.
What I need is
I have a Mysql table in which two fields are there one is auto_increment and next is name which is in varchar.
By using PHP I want to insert the more than one name at a time
Now I can able insert one by one but I want to insert more than one.
I want to create more textboxes with the same at backend I want to get that names in array and then I want to insert.

Pls help me how to generate multiple columns in php..

Thanks in Advance.
Your response will  help me more............
Jitendra Faye replied to sathish on 26-Jun-12 12:50 AM
As you told that you want to add column to table using php code, then use this sample code-

@mysql_query("ALTER TABLE `tablename` ADD `$colname` VARCHAR( 100 )") or die(mysql_error()); 

If you want to add more column then create one array of columns and using loop peform ALETR
command on table,

Hope this will help you.
sathish replied to Jitendra Faye on 26-Jun-12 02:13 AM
Thanks for your response...

But I dont want the back end mysql code, What I need is I want to create more textbox dynamically in php before submitting I want to enter the fields in textbox.
Anil Kumar replied to sathish on 18-Aug-12 05:57 AM
Hi Sathish,

I am writing the code below to insert values for textboxes using only one simple query. It will allow you to take the values from textboxes in the array named "values" in my code. Go through the code and connect back for anything you need.

you store values in array "values" from text boxes:
foreach($value as $key => $values){
@mysql_query("insert into `tablename` (name) values('"$value"')") or die(mysql_error()); 

Thanks and Regards
Anil K.