0

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.

6
  • 3
    use this code $row['config.primary_category'] Commented Oct 31, 2012 at 16:26
  • oh my god. the quotes get me every time! is that because it was a string? Commented Oct 31, 2012 at 16:29
  • Use var_dump instead of print_r to see in more detail what you're dealing with... Commented Oct 31, 2012 at 16:31
  • @liz The quotes are because the key is a string not an integer. php.net/manual/en/language.types.array.php Commented Oct 31, 2012 at 16:33
  • And set your error_reporting setting to -a and display_Errors=On in php.ini or using ini_set ... Commented Oct 31, 2012 at 16:56

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.