Hi,

I've been trying to output a value from multiple merged 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)!

Any help is appreciated, cassius.

Comments

Anonymous’s picture

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.

Anonymous’s picture

Bump

Anonymous’s picture

Bump

nancydru’s picture

I would suggest that you take a few minutes to learn about "foreach" loops and the "implode" function. You can write this with a couple of loops and probably two implodes. It should be very compact and scalable.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

summit’s picture

Hi, Anyone writing the loops and implode function please?
Thanks in advance!
greetings,
Martijn