I try to make my posts as short as possible, but you want details...
Currently I am using hand-coded queries that create a generic table...
##########New Table Configuration###################
$char=" VARCHAR ";//Set preferred character Type
$length="(100),";//set preferred length
$fieldname1="name1";//insert names here to be used
$fieldname2="name2";//for all new tables
$fieldname3="name3";
$fieldname4="name4";
$fieldname5="name5";
$field1=$fieldname1."".$char."".$length;
$field2=$fieldname2."".$char."".$length;
$field3=$fieldname3."".$char."".$length;
$field4=$fieldname4."".$char."".$length;
$field5=$fieldname5."".$char."".$length;
###########Create New Table and populate it##########################
$newtable.='CREATE TABLE `'.$etoPrefix."".$tmPrefix."".$table.'`';
$newtable.="(";
$newtable.="`id` INT(100) NOT NULL AUTO_INCREMENT,";
$newtable.=$field1;
$newtable.=$field2;
$newtable.=$field3;
$newtable.=$field4;
$newtable.=$field5;
$newtable.="PRIMARY KEY (`id`)";
$newtable.=")";
$newtable.=" TYPE=myisam;";
$etomite->dbQuery($newtable);
//enter dummy data for row 1 so that getIntTableRows has something to display
$sql = 'INSERT INTO `'.$etoPrefix."".$tmPrefix."".$table.'` (`id`, `name1`, `name2`, `name3`, `name4`, `name5`) VALUES (NULL, \'data1\', \'data2\', \'data3\', \'data4\', \'data5\');';
$etomite->dbQuery($sql);
I'm trying to extend that to allow for user input (via snippet call, form, whatever, it's fairly easy to get an array to use but I can't seem to integrate all the bits together).
I tried adapting formHandler foreach function with code like this:
$names=array([0]=>(name,age,phone));
$cnames=explode( " , " , $names );
$i=1:
$fname="fieldname";
foreach($cnames as $value){//I also tried $cnames as $key=>$value and other combos
$chunkNames.=$fname."".$i;
$column_name.=$value;
$newFields.=$value."".$char."".$length;
$i++;
}
Thinking that this would collect the following output:
return $chunkNames;
would show: fieldname1fieldname2fieldname3
return $column_name;
would show: nameagephone
return $newFields;
would show:name VARCHAR (100) age VARCHAR (100) phone VARCHAR (100)
However, this is the result for $newFields (the most important one for me at the moment).
nameagephone VARCHAR (100).
Obviously each array element is being included, but not appending the $char."".$length between the elements, just once at the end!
As mentioned, I tried a whole range of functions with a variety of syntax styles...
Quote
I have tried foreach(), while(), do while(), for()
But the result is always the same, it seems to loop, but not append the $variables between elements, only at the end...
Therefore...
Quote
How do I append a variable to each element of an array in a loop?
Edited by Cris D., 17 May 2007 - 11:25 AM.