0

I'm really stuck in this.

I need a result like (138,139,140,141,142,143,144,145), but I'm getting just a (Array,Array,Array,Array,Array,Array,Array,Array)...

My code is:

<?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;
    }
?>

Can you please help me?

Thanks a lot!

MRP0225
  • 3
  • 4
  • 1
    Your code is open to injections. Don't put user input directly into your query. Put a placeholder, `?`, where it should go, then pass `$_GET['cat']` in in the execute as an array. http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – chris85 Apr 25 '15 at 18:07

1 Answers1

2

Change

$category[] = array($row['product_category_id']);

for

$category[] = $row['product_category_id'];
pavel
  • 26,538
  • 10
  • 45
  • 61