Hi, I don't know if this is the right way to ask for assistance but here it comes:

I've been trying to output a single value from multiple cck fields in a table cell, and I could use some help.

I have three multiple-value fields ($field_one, $field_two, $field_three) stored using a cck made content type.

The stored values are:
$field_one (a1,a2,a3)
$field_two (b1,b2,b3)
$field_three (c1,c2,c3)

The intended output is (| as cell delimiter, - as value delimiter):

| a1-b1-c1 | a2-b2-c2 | a3-b3-c3 |

My current attempts are modified versions of

<?php foreach ((array)$field_one as $item) { ?>
<td><?php print $item['view'] ?></td>
<?php } ?>

but no matter how I try to modify it it wont work as intended (my php knowledge is severely limited)!

My best attempt so far is this code (but the .tpl.php gets bloated fast and the code isn't very scalable)

<?php if (content_format('field_one', $field_one[0]) > '' ||
        content_format('field_two', $field_two[0]) > ''  ||
        content_format('field_three', $field_three[0]) > '' ) : ?>
<td><?php print $node->field_one[0]['value'] ?>&ndash;
<?php print $node->field_two[0]['value'] ?>&ndash;
<?php print $node->field_three[0]['value'] ?>
</td>
<?php endif; ?>

<?php if (content_format('field_one', $field_one[1]) > '' ||
        content_format('field_two', $field_two[1]) > ''  ||
        content_format('field_three', $field_three[1]) > '' ) : ?>
<td><?php print $node->field_one[1]['value'] ?>&ndash;
<?php print $node->field_two[1]['value'] ?>&ndash;
<?php print $node->field_three[1]['value'] ?>
</td>
<?php endif; ?>

Any help is appreciated, cassius.

(cross-posted from http://drupal.org/node/159690)

Comments

Anonymous’s picture

Bump