- Posts: 45
COMMUNITY FORUM
[SOLVED] Load extra fields from a other item
- Gerben
-
Topic Author
- Offline
- Senior Member
Less
More
10 years 6 months ago - 10 years 6 months ago #133876
by Gerben
Load extra fields from a other item was created by Gerben
Hi Support,
I'm working on a project where i need to load extra fields from other specific item (with id 18) on a categorie item :)
So i have the following code that is getting all the extra fields from item 18.
<?php $db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('extra_fields')
->from('#__k2_items')
->where('id= 18');
$db->setQuery($query);
$extrafields = $db->loadObjectlist();
?>
How can i encode this string so i can echo every extra field on its selve?
Really breaking my head about it :)
Hope that someone can push me in the right direction.
I'm working on a project where i need to load extra fields from other specific item (with id 18) on a categorie item :)
So i have the following code that is getting all the extra fields from item 18.
<?php $db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('extra_fields')
->from('#__k2_items')
->where('id= 18');
$db->setQuery($query);
$extrafields = $db->loadObjectlist();
?>
How can i encode this string so i can echo every extra field on its selve?
Really breaking my head about it :)
Hope that someone can push me in the right direction.
Last edit: 10 years 6 months ago by Gerben.
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
10 years 6 months ago #133902
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic Load extra fields from a other item
Hi Gerben,
A better approach is to use the K2Item model object.
A better approach is to use the K2Item model object.
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- Gerben
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 45
10 years 6 months ago #133906
by Gerben
Replied by Gerben on topic Load extra fields from a other item
Hi Mohamed.
Thank you for your answer but i want to do it manualy.
the var_dump gives me this:
array(1) { [0]=> object(stdClass)#284 (1) { ["extra_fields"]=> string(1556) "[{"id":"1","value":"009d3e"},{"id":"2","value":"005c25"},{"id":"3","value":"ffed00"},]" } }
It must be possible to just echo the value of id 2 but i can not manage to fix this until so far.
Somebody had any idea?
Cheers
Thank you for your answer but i want to do it manualy.
the var_dump gives me this:
array(1) { [0]=> object(stdClass)#284 (1) { ["extra_fields"]=> string(1556) "[{"id":"1","value":"009d3e"},{"id":"2","value":"005c25"},{"id":"3","value":"ffed00"},]" } }
It must be possible to just echo the value of id 2 but i can not manage to fix this until so far.
Somebody had any idea?
Cheers
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
10 years 6 months ago - 10 years 6 months ago #133928
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic Load extra fields from a other item
No problem, it can be done by this code
BTW, the query you used will return only one value, so it is better to use $db->loadResult() instead of $db->loadObjectList()
require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
$json = new Services_JSON;
$jsonObjects = $json->decode($extrafields[0]);
BTW, the query you used will return only one value, so it is better to use $db->loadResult() instead of $db->loadObjectList()
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Last edit: 10 years 6 months ago by Mohamed Abdelaziz.
Please Log in or Create an account to join the conversation.
- Gerben
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 45
10 years 6 months ago #133934
by Gerben
Replied by Gerben on topic Load extra fields from a other item
Thank you Mohamed for your help.
I managed it by doing:
require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
?>
<?php $db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('extra_fields')
->from('#__k2_items')
->where('id= 18');
$db->setQuery($query);
$extrafields = $db->loadResult();
require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
$json = new Services_JSON;
$jsonObjects = $json->decode($extrafields);
echo $jsonObjects[3]->value;
?>
<? print_r($jsonObjects);?>
I managed it by doing:
require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
?>
<?php $db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('extra_fields')
->from('#__k2_items')
->where('id= 18');
$db->setQuery($query);
$extrafields = $db->loadResult();
require_once (JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
$json = new Services_JSON;
$jsonObjects = $json->decode($extrafields);
echo $jsonObjects[3]->value;
?>
<? print_r($jsonObjects);?>
Please Log in or Create an account to join the conversation.