views:

38

answers:

2

Hi friends,

I'm a drupal newbie...

I researched but couldnot find :/ is there any predefined variable that gives my CCK field value count?

for example; I have field_logo_sponsor and I need to display all logo items. Now I have 5 item

<?php print $node->field_logo_sponsor[0]['view'] ?>
<?php print $node->field_logo_sponsor[1]['view'] ?>
<?php print $node->field_logo_sponsor[2]['view'] ?>
<?php print $node->field_logo_sponsor[3]['view'] ?>
<?php print $node->field_logo_sponsor[4]['view'] ?>

it is stupid to use it that way :/ if there is any count variable for that, I will just create a loop for that and display them in a for or while loop

Appreciate helps! thanks a lot!

+2  A: 

How about:

<?php
foreach($node->field_logo_sponsor as $logo_sponsor) {
  print $logo_sponsor['view'];
}
?>

Also count($node->field_logo_sponsor) should return you the number of items.

sirhc
working great! thanks! :) silly me, how come I could not think of that! :)
artmania
A: 

Sidenote: never use

foreach($node->field_logo_sponsor as $logo_sponsor) {
  print $logo_sponsor['value'];
}

Even if that calue contains what you want, and the view does not contain the HTML you want. value is unescaped, meaning, it can (and therefore will, at some point) contain stuff like XSS.

berkes