【问题标题】:How to end a cycle with DIV ?如何用 DIV 结束一个循环?
【发布时间】:2026-01-11 09:20:03
【问题描述】:
<div class="product-fields">

<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted['normal'] as $field) { // I set the position to normal

if ( $field->is_hidden )
continue;
if ($field->display) {
?>

<?php if ($field->custom_title != $custom_title) { ?>

 <div class="product-field product-field-type-<?php echo $field->custom_title ?><?php //echo $field->field_type ?>">

<div class="product-fields-title"><?php echo JText::_($field->custom_title); ?></div>

<?php
if ($field->custom_tip)
 echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
}
?>
<span class="product-field-display"><?php echo $field->display ?></span>
<!--<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>-->

  <?php $custom_title = $field->custom_title; }

}
echo "<br /><br />&raquo;171717&raquo;</div>";

?>

我想有一个更接近的 DIV 在周期的和

<span class="product-field-display"><?php echo $field->display ?></span>

但我不知道放在哪里

echo "<br /><br />&raquo;171717&raquo;</div>";

【问题讨论】:

    标签: php cycle


    【解决方案1】:

    正确关闭 Div 标签:

    <?php
    $custom_title = null;
    foreach ($this->product->customfieldsSorted['normal'] as $field) { // I set the position to normal
    
    if ( $field->is_hidden )
    continue;
    if ($field->display) {
    ?>
    
    <?php if ($field->custom_title != $custom_title) { ?>
    
     <div class="product-field product-field-type-<?php echo $field->custom_title; //echo $field->field_type ?>">
    
    <div class="product-fields-title"><?php echo JText::_($field->custom_title); ?></div>
    
    <?php
    if ($field->custom_tip)
     echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
    }
    ?>
    <span class="product-field-display"><?php echo $field->display ?></span>
    <!--<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>-->
    
      <?php $custom_title = $field->custom_title; }
    ?>
    </div>
    <?php
    }
    echo "<br /><br />&raquo;171717&raquo;";
    ?>
    </div>
    

    【讨论】:

    • 我会在单个的末尾获得一个
      相反,我在单个 display ?>跨度>