PHP PDO MYSQL - 获取与 fetchAll 逗号分隔的数组
PHP PDO MYSQL - Get Array comma separated from fetchAll
我真的卡在这里面了。
我需要像 (138,139,140,141,142,143,144,145) 这样的结果,但我得到的只是一个 (Array,Array,Array,Array,Array,Array,Array,Array)...
我的代码是:
<?php
try {
$dbconn = DBCONNECTION();
$sql = "SELECT `product_category_id`, `product_category_parent_id`, `date_available`, `status`
FROM `product_category`
WHERE `product_category_parent_id` = '" . $_GET['cat'] . "'
AND `date_available` <= NOW()
AND `status` = '1'
ORDER BY `product_category_id` ASC";
$stmt = $dbconn -> prepare($sql);
$stmt -> execute();
$array = $stmt -> fetchAll(PDO::FETCH_ASSOC);
foreach($array as $row) {
$category[] = array($row['product_category_id']);
}
$subcategory = implode(',', $category);
echo $subcategory;
}
?>
你能帮帮我吗?
非常感谢!
改变
$category[] = array($row['product_category_id']);
对于
$category[] = $row['product_category_id'];
我真的卡在这里面了。
我需要像 (138,139,140,141,142,143,144,145) 这样的结果,但我得到的只是一个 (Array,Array,Array,Array,Array,Array,Array,Array)...
我的代码是:
<?php
try {
$dbconn = DBCONNECTION();
$sql = "SELECT `product_category_id`, `product_category_parent_id`, `date_available`, `status`
FROM `product_category`
WHERE `product_category_parent_id` = '" . $_GET['cat'] . "'
AND `date_available` <= NOW()
AND `status` = '1'
ORDER BY `product_category_id` ASC";
$stmt = $dbconn -> prepare($sql);
$stmt -> execute();
$array = $stmt -> fetchAll(PDO::FETCH_ASSOC);
foreach($array as $row) {
$category[] = array($row['product_category_id']);
}
$subcategory = implode(',', $category);
echo $subcategory;
}
?>
你能帮帮我吗?
非常感谢!
改变
$category[] = array($row['product_category_id']);
对于
$category[] = $row['product_category_id'];