我获取total_amount值并插入到另一个表中,但我想在一个字段中插入total_amount,并用",“分隔。如何做到这一点?

我知道Mysqli是最新版本。但在这里,mysql运行正常。
<?php
include('database/db.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$sql1="Insert into test(`total_amount`) values ('{$_POST['i']}')";
$result1=mysql_query($sql1);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Page</title>
</head>
<body>
<form name="" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<tr>
<td>Total Amount</td>
</tr>
<?php
$sql="Select * from tes1";
$result=mysql_query($sql);
while($dtset=mysql_fetch_array($result))
{
?>
<tr>
<td><input type="hidden" name="i" value="<?php echo $dtset['total_amount'];
?>"><?php echo $dtset['total_amount']; ?></td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>发布于 2017-07-09 14:46:45
<?php
$sql="Select * from tes1";
$result=mysql_query($sql);
// Empty array
$amounts = [];
while($dtset=mysql_fetch_array($result))
{
// Push the amounts to the array.
$amounts[] = $dtset['total_amount'];
}
// Implode will create a string from your array and seperates it with
// the chosen character
$combined = implode(",",$amounts);
?>
<tr>
<td>
<input type="hidden" name="i" value="<?php echo
$combined; ?>">
<?php echo $combined; ?>
</td>
</tr>while循环现在不是表行的一部分,而是首先创建包含所有值的数组,然后您可以将通过内爆创建的字符串添加到隐藏的表单字段中。
https://stackoverflow.com/questions/44993512
复制相似问题