The Script:
脚本:
<?php
$tqs = "SELECT * FROM `table_two`";
$tqr = mysqli_query($dbc, $tqs);
$row = mysqli_fetch_assoc($tqr);
$thearray[] = $row['some_text_id'];
// Prints e.g.: Array ( [0] => 164, 165, 166 )
print_r($thearray);
echo "<br/><br/>";
echo "<br/><br/>";
$thearray = explode(", ", $thearray);
print_r($thearray);
?>
I have the following entry in one row of the column "some_text_id":
在“some_text_id”列的一行中有以下条目:
164, 165, 166
I am looking to "explode" this by the comma and have it stored in an array, so I can select the numbers individually, e.g.:
我希望用逗号“爆炸”它,并将它存储在一个数组中,因此我可以分别选择数字,例如:
myarray[0], myarray[1], myarray[2]
Though I am getting the following error message:
虽然我得到以下错误信息:
Warning: explode() expects parameter 2 to be string, array given in ... (points to the explode function)
警告:explosion()期望参数2是string,数组在…(指向爆炸函数)
Any suggestions on how to do this?
有什么建议吗?
1 个解决方案
#1
5
Skip the part where you put the database results into an array. It's completely unnecessary:
跳过将数据库结果放入数组的部分。这是完全不必要的。
<?php
$tqs = "SELECT * FROM `table_two`";
$tqr = mysqli_query($dbc, $tqs);
$row = mysqli_fetch_assoc($tqr);
// Prints e.g.: 164, 165, 166
print_r($row['some_text_id']);
echo "<br/><br/>";
echo "<br/><br/>";
$thearray = explode(", ", $row['some_text_id']);
print_r($thearray);
?>
#1
5
Skip the part where you put the database results into an array. It's completely unnecessary:
跳过将数据库结果放入数组的部分。这是完全不必要的。
<?php
$tqs = "SELECT * FROM `table_two`";
$tqr = mysqli_query($dbc, $tqs);
$row = mysqli_fetch_assoc($tqr);
// Prints e.g.: 164, 165, 166
print_r($row['some_text_id']);
echo "<br/><br/>";
echo "<br/><br/>";
$thearray = explode(", ", $row['some_text_id']);
print_r($thearray);
?>