我目前有这个返回数组的查询,但是如何输出这个数组只是作为Thomas,James。因为我想将它以那种格式存储在变量中,我可以稍后调用。这是一个foreach?感谢
$stmt = $conn->prepare("SELECT admin_name FROM adminuser_tbl");
if ($stmt->execute()) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
输出:
Array ( [admin_name] => Thomas [0] => Thomas ) Array ( [admin_name] => James [0] => James )
答案 0 :(得分:0)
而不是
print_r($row);
怎么样......
$name = join(", ", $row);
或者您可以将结果连接到一个名称数组
$stmt = $conn->prepare("SELECT admin_name FROM adminuser_tbl");
$names = array();
if ($stmt->execute()) {
while ($row = $stmt->fetch()) {
$names[] = join(", ", $row);
}
}