liz
liz

Reputation: 483

get specific array data from json with php / mysql

i have a field in my database that is encoded in json. i think. (part of a joomla/zoo installation). i need to retrieve a specific value from it (primary_category).

i have enclosed the following code in my template that displays the data

   $database = &JFactory::getDBO();
$sql = "SELECT params FROM #__zoo_item";
    $database->setQuery( $sql );
$row=$database->loadResult();
$row = json_decode($row, TRUE);
print_r($row);

that returns the below...

Array ( [metadata.title] => [metadata.description] => [metadata.keywords] => [metadata.robots] => [metadata.author] => [config.enable_comments] => 1 [config.primary_category] => 601 ) 

what i need to do is just grab the 601 value. i have tried $row[config.primary_category] and $row[6] but neither work.

i am not sure (since i really dont know what i am doing) if i did the json decode wrong or if its a problem with the way i am accessing the array.

Upvotes: 0

Views: 408

Answers (1)

Tariq Aziz
Tariq Aziz

Reputation: 798

use this code $row['config.primary_category']

Upvotes: 1

Related Questions