Re: syntax question

From: Date: Wed, 19 Feb 2003 17:34:31 +0000
Subject: Re: syntax question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-136217@lists.php.net to get a copy of this message
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 ....................................... Ernest E Vogelsinger" <ernest@vogelsinger.at > No. The reason for the comma is that SQL dictates that column names in a > create table statement are separated by a comma. > > This is valid SQL: > create table chairs( > id int(5), > item varchar(50), > desc text, > price float > ); > > This is invalid and generates an SQL error when passed to the server: > create table chairs( > id int(5) > item varchar(50) > desc text > price float > );

« previous php.general (#136217) next »