Hi,
Thursday, February 20, 2003, 3:34:31 AM, you wrote:
AR> This is what I was getting at.
AR> The following is correct mysql syntax in which a comma must be added after
AR> each field - except for the last field - in this case price:
AR> i.e.,
AR> .................
AR> CREATE TABLE chairs(
AR> id int(5),
AR> item varchar(50),
AR> desc text,
AR> price float
AR> );
AR> .........................
AR> However, within the loop in her script it says to add the comma after _each_
AR> field since there is no way of knowing when the loop will end.
AR> Thus, why is she directing the script - after the loop has ended - to lop
AR> off the last comma by using the
AR> substr() function call
you can rework the logic a bit and only add a comma if it is not the first run
through the loop :
$sql = "CREATE TABLE $table_name (";
for ($i = 0; $i < count($field_name); $i++) {
if($i) $sql .= ','; //first time i = 0 and this line ignored
$sql .= "$field_name[$i] $field_type[$i]";
if ($field_length[$i] != "") {
$sql .= " ($field_length[$i]),";
}
}
$sql .= ")";
But you are right there was a need to nuke the comma in the original script
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php