剧本:
<?php
if(isset($_POST['submit'])) {
$some_text_1 = $_POST['some_text_1'];
$some_text_2 = $_POST['some_text_2'];
$some_text_3 = $_POST['some_text_3'];
$myarray = array($some_text_1, $some_text_2, $some_text_3);
for ($i = 0; $i < count($myarray); $i++) {
$tqs = "INSERT INTO `table` (`some_text`) VALUES ('" . $myarray[$i] . "')";
$tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc));
$tqs = "SELECT `id` FROM `table` WHERE `some_text` = '" . $myarray[$i] . "'";
$tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc));
$fetch_array[] = mysqli_fetch_array($tqr);
}
$fetch_array = implode(", ", $fetch_array);
?>
我希望将数组插入到一行中,如下例所示:
the_row: | 3, 4, 5, 6, 7
虽然在使用implode函数时我收到此错误:
Notice: Array to string conversion in ... (points to the implode function)
有关如何使其正常工作的任何建议吗?
答案 0 :(得分:1)
implode()
需要一个字符串数组作为第二个参数。你给它一个数组数组。
你可以用这样的东西来解决这个问题(只是一个例子):
$row = mysqli_fetch_array($tqr);
$fetch_array[] = row['id'];