View Single Post
Old 04-01-2004, 08:46 PM   #2 (permalink)
Moskie
Pure Chewing Satisfaction
 
Moskie's Avatar
 
Location: can i use bbcode [i]here[/i]?
I think the problem is that the last time this for loop goes through:

PHP Code:
$sql "CREATE TABLE $_POST[table_name] (";

for (
$i 0$i count($_POST[field_name]); $i++) {

    
$sql .= "$_POST[field_name][$i$_POST[field_type][$i]";

    if (
$_POST[field_length][$i] != "") {

    
$sql .= " ($_POST[field_length][$i]), ";

    } else {

        
$sql .= ", ";

    }


... you're left with an extra comma at the end.

Do a check to see if you're at the last iteration of the loop. If you are, don't print the comma. Hopefully that helps.

Such as:

PHP Code:
$sql "CREATE TABLE $_POST[table_name] (";

for (
$i 0$i count($_POST[field_name]); $i++) {

    
$sql .= "$_POST[field_name][$i$_POST[field_type][$i]";

    if (
$_POST[field_length][$i] != "") {

    
$sql .= " ($_POST[field_length][$i]) ";

    } 

if (
$i $_POST[field_name]-1) {
    
$sql .= ", ";
}


__________________
Greetings and salutations.

Last edited by Moskie; 04-01-2004 at 08:52 PM..
Moskie is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73