Unable to get fieldparams as array or object Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
chattago2002
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Jan 18, 2019 11:06 am

Unable to get fieldparams as array or object

Post by chattago2002 » Fri Jan 18, 2019 11:32 am

Hi everybody.

I would get Joomla custom fields values from a PHP script. I include all necessary files and I can read checkbox values from "fields" table, the "fieldparams" column.
If I execute this code

Code: Select all

$query = "select #__fields.fieldparams from   #__fields where  #__fields.id = 19";
$db->setQuery($query);
$result = $db->loadRowList();
foreach ($result as $value) {
	echo gettype($value); // 01
	echo $value[0]; // 02
	$var = json_encode($value[0]);
	echo gettype($var); // 03
}
the type of $value is "Array" (step 01), so if I access to $value[0] the result (step 02) is the global list (so I suppose this is an Array with 1 element)

Code: Select all

{
"options":{
        "options0":{"name":"type1","value":"1"},
        "options1":{"name":"type2","value":"2"},
        "options2":{"name":"type3","value":"3"},
        "options3":{"name":"type4","value":"4"},
        "options4":{"name":"type5","value":"5"}
    }
}
but when I try to use json_encode the result (step 03) is a string.
In this way I can't access to keys and relative values.

What's wrong?
Last edited by toivo on Fri Jan 18, 2019 11:45 am, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2897
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Unable to get fieldparams as array or object

Post by SharkyKZ » Fri Jan 18, 2019 1:19 pm

Run json_decode(), not json_encode().

chattago2002
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Jan 18, 2019 11:06 am

Re: Unable to get fieldparams as array or object

Post by chattago2002 » Tue Jan 22, 2019 11:21 am

Thank you very much @SharkyKZ


Locked

Return to “Joomla! 3.x Coding”