I'm trying to get the Array so i can loop it through and get the category_id from it. Its output is in Odd behavior, 1st it comes in Public Row, then Public Rows, and then Num Rows. I'm not able to loop to these object as the loop code terminated in the 1st Row only and not going further in Rows. Basically, the output query returns like this:
array (size=3)
'row' =>
array (size=2)
'product_id' => string '50' (length=2)
'category_id' => string '20' (length=2)
'rows' =>
array (size=2)
0 =>
array (size=2)
'product_id' => string '50' (length=2)
'category_id' => string '20' (length=2)
1 =>
array (size=2)
'product_id' => string '50' (length=2)
'category_id' => string '28' (length=2)
'num_rows' => int 2
I'm trying to get the simple array so i can loop it dynamically and get the desired output. Here's my PHP code:
$categories = (array)$this->db->query("SELECT * FROM " . DB_PREFIX ."product_to_category WHERE product_id=50");
var_dump($categories);
However I've converted the Object into Array by prefixing (array) to the query but it doesn't worked for me as its still in object. Please suggest me as its taking too much time to settle this problem????
I DON'T KNOW WHY THIS IS COMING IN OBJECT?? BUT I GOT THE SOLUTION'S USING var_dump($categories['rows']);
If anybody know the exact solution your help might be acceptable.