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!

1
  • 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. stackoverflow.com/questions/60174/… Commented Apr 25, 2015 at 18:07

1 Answer 1

2

Change

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

for

$category[] = $row['product_category_id'];
Sign up to request clarification or add additional context in comments.

1 Comment

Oh god... So easy...! Thanks a lot @panther!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.