Pulling data from a single Extra Field Group

  • Ancellmktg
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 11 months ago - 10 years 11 months ago #1755 by Ancellmktg
Hi there,

I'm using this piece of code:
Code:
<?php $extraFieldsByGroup = JArrayHelper::pivot($this->item->extra_fields, 'group'); $db = JFactory::getDbo(); $query = "SELECT * FROM #__k2_extra_fields_groups"; $db->setQuery($query); $groups = $db->loadAssocList('id'); foreach ($extraFieldsByGroup as $key=>$extrafields){ $defaultGroup = ''; if(!is_array($extrafields)) $extrafields = array($extrafields); if($key == $this->item->category->extraFieldsGroup) $defaultGroup = "class='mefg_default'"; ?> <div id="group" class="<?php echo $groups[$key]['name'];?>" > <div class="<?php echo $groups[$key]['name'];?>"> <div> <h3><?php echo JText::_($groups[$key]['name']); ?></h3> </div> <ul> <?php foreach ($extrafields as $key=>$extraField): ?> <?php if($extraField->value != ''): ?> <?php /*?><li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"><?php */?> <?php if($extraField->type == 'header'): ?> <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4> <?php else: ?> <div> <span class="itemExtraFieldsLabel"><?php echo JText::_($extraField->name); ?>:</span> <span class="itemExtraFieldsValue <?php echo $extraField->alias; ?>"><?php echo $extraField->value; ?></span></div> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> </div></div> <?php } ?> <div class="clr"></div>

The problem there is that it loops through each extra field group. What I'd like to do is pull data from a single Extra Field Group and display it in a loop. It's going to be used as a color swatch, so the "value" will need to be used as a css class, IE:
Code:
<div class="swatch <?php echo $extraField->value; ?>">

So the value has to be specific to the group, and since there's going to be multiple colors which may not all be selected at the same time, I cant create a div for each one.

Any help would be appreciated.
Last edit: 10 years 11 months ago by Ancellmktg.

Please Log in or Create an account to join the conversation.

More
10 years 11 months ago #1756 by mmmaug1977
Replied by mmmaug1977 on topic Pulling data from a single Extra Field Group
Hi Robert,

The $extraFieldsByGroup in this case is an array indexed with group id, so if you want to access the extra fields of a group, with id=2 for example, try this code:
Code:
<div class="swatch <?php echo $extraFieldsByGroup[2]->extraFields->FieldAlias->value; ?>">
Where FieldAlias is substituted with the alias of the field you want to output its value.

Please Log in or Create an account to join the conversation.

  • Ancellmktg
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 11 months ago #1757 by Ancellmktg
Replied by Ancellmktg on topic Pulling data from a single Extra Field Group
Hi Mohamed,

What I'm trying to do is only loop through the data from a specific group, not all.

How would I go about doing that? If possible, I could pay a small fee for help with this matter.

Please Log in or Create an account to join the conversation.

More
10 years 11 months ago #1758 by mmmaug1977
Replied by mmmaug1977 on topic Pulling data from a single Extra Field Group
Hi Robert,

Yes it is possible, just send the access details of your website: Joomla backend admin, and FTP access to sales @ joomreem dot com, and I will reply to you with the cost and how do it for you.

Please Log in or Create an account to join the conversation.

  • Ancellmktg
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 11 months ago #1759 by Ancellmktg
Replied by Ancellmktg on topic Pulling data from a single Extra Field Group
Hi Mohamed,

Email has been sent.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum