CCK field value count never less than 1 or NULL
Ive got a CCK field set up so that unlimited values can be entered upon node creation (Number of values: unlimited)
When i try to print values in a node with
if ($node->field_tip != NULL)
foreach ((array)$node->field_tip as $tip) {
print "<div class='tip'>" . $tip['view'] ."<开发者_如何学编程/div>";
};
or print
count($node->field_tip);
the value is never less than 1, and <div class='tip'></div>
is always displayed, even if there isn't any values entered in that field.
The CCK field will never be null in Drupal 6. Even if the field has no values, it will still be an array containing a single item. You can check that the view attribute of each item is not empty before printing the div:
foreach ($node->field_tip as $tip) {
if(!empty($tip['view'])) {
print "<div class='tip'>" . $tip['view'] ."</div>";
}
}
精彩评论