开发者

how to get date from database and display without any repetition?

I had a function which is pulling all the dates from database against each record.

public function getAllYears() {

    $collection = Mage::getModel('press/press')->getCollection()->getYears();

    return $collection;

}

and am displaying it as :

<?php  

        $coll =  $this->getAllYears();

    ?>


         <?php foreach ($coll as $list): ?>

                <?php echo $list["year"]; ?>
         <?php endforeach; ?>

It is giving me all the years(dates), without caring for repetitio开发者_开发知识库n, whereas I want is same date must not be repeated.

Mean same year must not repeat. Any help?


Perhaps change the display code to:

<?php
$years = array();
$coll =  $this->getAllYears();
foreach ($coll as $list)
    $years[] = $list['year'];
$years = array_unique($years);
?>

<?php foreach ($years as $year): ?>
<?php echo $year; ?>
<?php endforeach; ?>


How about:

<?php  
$coll =  $this->getAllYears();

$lastyear
foreach ($coll as $list)
{
    if($list["year"] != $lastyear) {
    echo $list["year"];
}
$lastyear = $list["year"]
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜