怎么样,我在a中输入了一系列数字,用逗号(,)分隔
当我们按下send按钮时,这些数字中的每一个都被输入到bd中,具有不同的id。
例子:
我们进入
values = 5,6,7,8,9
在bd中,它们是这样保存的:
Id values
1 5
2 6
3 7
4 8
5 9
我想加一个
例子:
进入
值=5,6,7,8,9
我们进入
cost = 100
我想在进入这个系列时[5,6,7,8,9]
对他们来说,成本是100
也就是说,在bd中以这种方式保存:
Id values cost
1 5 100
2 6 100
3 7 100
4 8 100
5 9 100
代码:
索引文件
<html>
<head>
<title></title>
<meta name="robots" content="noindex, nofollow" />
</head>
<body>
<form method="POST" action="process_values.php">
<p><textarea rows="20" name="values" cols="40"></textarea></p>
<input type="text" name="cost" value="" placeholder="cost">
<p><input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>
处理值.php
<?php
error_reporting(-1);
ini_set("display_errors", 1);
$value = $_POST["values"]; //We receive textarea values
$valore = chop($value); // Eliminate line breaks and space, but only at the end of the chain
$val = nl2br($valore); // We add the line breaks <br />
$array_datos = explode(",", $val); // Create an array with the received data using as a separator (,)
foreach ($array_datos as $value) // We create a foreach loop
{
include("$_SERVER[DOCUMENT_ROOT]/CN/connexion.php");
$_SAVE_SQL = "INSERT INTO nombre_tabla (values) VALUES ('".$value."')";
$mysqli->query($_SAVE_SQL);
}
?>
<html>
<body>
</table>
<table border="1" width="600" id="table1">
<tr>
<td>ID</td>
<td>VALUES</td>
</tr>
<?PHP
/*******************************************************************************
* CONSULTING DATA TO THE BD
*******************************************************************************/
if ($res = $mysqli->query("SELECT * FROM table_name ORDER BY id ASC", MYSQLI_USE_RESULT)) {
/*******************************************************************************
* The while loop that runs through each record and shows each field in the table.
*******************************************************************************/
while ($row = mysqli_fetch_array($res)){
echo "
<tr>
<td>".$row['id']."</td>
<td>".$row['values']."</td>
</tr>
";
}
}
?>
</body>
</html>