0

作为一个小组发现的结果,我得到了类似的东西

id   name                               date            project
2898 Noemi Araceli Farre Gutierrez      2012-07-23      mr12249-Northgate Field  
2898 Noemi Araceli Farre Gutierrez      2012-07-24      mr12251-Marketon Field  
2898 Noemi Araceli Farre Gutierrez      2012-07-25      mr12251-Marketon Field  
2898 Noemi Araceli Farre Gutierrez      2012-07-26      mr12249-Northgate Field 
3047 Mauricio Javier García             2012-07-22      mr12249-Northgate Field  
3047 Mauricio Javier García             2012-07-23      mr12251-Marketon Field  
3047 Mauricio Javier García             2012-07-26      mr12251-Marketon Field 

在我看来,我需要避免重复 id 和 name,并显示如下:

id   name                               date            project
2898 Noemi Araceli Farre Gutierrez      2012-07-23      mr12249-Northgate Field  
                                        2012-07-24      mr12251-Marketon Field  
                                        2012-07-25      mr12251-Marketon Field  
                                        2012-07-26      mr12249-Northgate Field 
3047 Mauricio Javier García             2012-07-22      mr12249-Northgate Field  
                                        2012-07-23      mr12251-Marketon Field  
                                        2012-07-26      mr12251-Marketon Field 

我可以通过比较视图中 foreach 循环期间的当前值和先前值来做到这一点,但在我看来,必须有更好的蛋糕方式。

4

1 回答 1

1

没有“更好的蛋糕方式”。这是一个简单的 PHP 逻辑。

$currentName = null;
foreach ($results as $row) {
    if ($row['name'] != $currentName) {
        $currentName = $row['name'];
        echo $currentName;
    }
    else {
        // Do not display anything
        // you may need to echo some tab characters or something to keep
        // the table formatted
    }
}
于 2012-07-28T05:11:16.480 回答