The column list is a comma seperated list, the last column cannot have a comma after it or the SQL server will expect another column to be listed.
However in that code segment it is not trying to determine if there is or is not a column, it is simply attempting to add the (length) attribute to the column getting created. Regardless of length being specified, a comma is assumed to be needed to be appended to the $sql string during the loop.
Then as you have already stated, the last comma is removed after the loop is completed. This should result in the correct SQL syntax as you shown.
Hope that helps ...
Jason k Larson
Anthony Ritter wrote:
This is what I was getting at. The following is correct mysql syntax in which a comma must be added after each field - except for the last field - in this case price:i.e., ................. CREATE TABLE chairs( id int(5), item varchar(50), desc text, price float ); ......................... However, within the loop in her script it says to add the comma after _each_ field since there is no way of knowing when the loop will end. Thus, why is she directing the script - after the loop has ended - to lop off the last comma by using the substr() function call as in: if ($field_length[$i] != "") { $sql .= "($field_length[$i]) , "; } else { $sql .= ", "; } loop is finished. and then... $sql=substr($sql,0,-1); //which basically says to take the existing sql statement string from the beginning to the next to last character and return it to the variable $sql thus taking off the comma. Am I on the right track? Thank you. Tony Ritter .......................................
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php