我目前正在使用json_encode将数组转换为字符串 在我的表格中以直线模式输出数据
user
-----------
id | name
-------------------------------------------
1 |"name1","name2","name3","name4","name5"
但是我想要一个表格数据看起来像这样的输出。
user
-----------
id | name
-----------
1 | name1
2 | name2
3 | name3
4 | name4
5 | name5
我的PHP代码
<?php
$connect = mysqli_connect("localhost", "root", "", "dbsample");
if(isset($_POST["check_val"])){
$check_val = htmlspecialchars(strip_tags("check_val"));
$number = json_encode($_POST["name"]);
for ($i = 0; $i < count($number); $i++) {
if ($number[$i] != "") {
$query = "INSERT INTO tbl_name(name) VALUES (?)";
$stmt = $connect->prepare($query);
$number[$i] = htmlspecialchars(strip_tags($number[$i]));
$stmt->bind_param("s", $number);
if($stmt->execute()) {
echo "SUCCESS";
# code...
}else
{
echo "ERROR";
}
}
else{
echo "Please Enter Name";
}
}
}
?>