【发布时间】:2015-04-25 18:01:44
【问题描述】:
我真的陷入了困境。
我需要一个类似 (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;
}
?>
你能帮帮我吗?
非常感谢!
【问题讨论】:
-
您的代码对注入开放。不要将用户输入直接放入您的查询中。将占位符
?放在它应该去的地方,然后将$_GET['cat']作为数组传入执行中。 stackoverflow.com/questions/60174/…