Using a For loop to create a table
Posted: Sat Oct 02, 2004 10:17 pm
feyd | Please use
What is happening is, a page takes a desired table name and the number of fields and hands it to the next page. This second page creates the number of desired fields and then you select the name of the fields aong with the field type. The final page takes the information and puts it in to a database.
This piece of code is supposed to create the table with the correct amount of fields and field types.
I receive this error upon exceution:
Any help is greatly appreciated.
Wade
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
10022004 2213 GMT-6
Im learning PHP from an older book so Im taking the code and trying to figure out how to use it with the new globles variable off.
This bit of code Im having trouble with.Code: Select all
$sql = "CREATE TABLE $t_name (";
for ($i = 0; $i < count($f_name); $i++) {
$sql .= "$f_name[$i] $f_type[$i]";
if ($f_length[$i] !="") {
$sql .= " ($f_length[$i] ), ";
} else {
$sql .= ", ";
}
}
$sql .= ")";What is happening is, a page takes a desired table name and the number of fields and hands it to the next page. This second page creates the number of desired fields and then you select the name of the fields aong with the field type. The final page takes the information and puts it in to a database.
This piece of code is supposed to create the table with the correct amount of fields and field types.
I receive this error upon exceution:
Code: Select all
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ї\\''table_name\\''] (A A (A ), )' at line 1Wade
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]