Rewriting a Foreach section of code

Discussion in 'PHP' started by Scubasjl, Apr 2, 2010.

  1. #1
    I have this section of code that is displaying all entries within this table. Wondering how I can rewrite it so that it still shows the name and value by choosing the ID of the name and value.

    I have figured out that its this line that makes it show all of them but thats as far as my knowledge goes.
    <?php foreach ($item->extra_fields as $extraField): ?>
    Code (markup):
    Full Section of code

          <?php if($params->get('itemExtraFields') && count($item->extra_fields)): ?>  
    <b><?php echo JText::_('Additional Info'); ?></b>
          <ul class="moduleItemExtraFields">
            <?php foreach ($item->extra_fields as $extraField): ?>
    				<li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
    					<span class="moduleItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
    					<span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
    					<br class="clr" />		
    				</li>
            <?php endforeach; ?>
          </ul>
          <?php endif; ?>
    Code (markup):
     
    Scubasjl, Apr 2, 2010 IP
  2. webria

    webria Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You may write a function namely function($id){ // do activities and return name and value array based on the id above}
    and call the function at the place you need.
     
    webria, Apr 2, 2010 IP