Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding SQL fields on the fly.. 1

Status
Not open for further replies.

Thomas001

Programmer
Jun 24, 2004
29
US
How would I go about adding multiple fields to a MySQL database that a user can specify within the same page?
 
I know how to implement the for() loop.. But I don't know a good way to add multiple fields into my database.
 
You could use the ALTER TABLE MySQL command.

I'm pretty sure you could utilize "ALTER TABLE table_name ADD field_1 INT, ADD field_2 varchar(255), ..."

So, with the for loop, you could build your syntax.

$sql = "ALTER TABLE table_name ";

for ($i = 0; $i < $num_fields; $i++) {
$sql .= " ADD $field_name field_desc, ";
}

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top