作为小组发现的结果,我得到类似
的内容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和名称,并显示如下:
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循环期间的当前值和之前的值来做到这一点,但在我看来,必须有一个更好的,蛋糕方式。
答案 0 :(得分: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
}
}