我想使用在其外部的 while 循环中创建的变量。这是因为我想将不同的变量放在彼此之后(逗号分隔)并放入字符串变量中。之后,我将删除最后一个逗号。
这是我的代码
$result = mysql_query("SELECT * FROM ".$_POST['moduleName']);
while($row = mysql_fetch_array($result))
{
//read fieldnames from database
$fieldName = $row['modFieldName'];
//creating a variable with the fieldname
$fieldName = 'field'.$fieldName;
//fill Variable with posted input
$fieldName = $_POST[$row['modFieldName']];
//Put fieldname in a string (outputs: a,b,c,d,e,)
$postString = $fieldName.",";
}
//Remove last comma
$postString = substr($postString,0,-1);
echo $postString;