为重复行创建空白行 [英] Creating blank row for repeating row

查看:91
本文介绍了为重复行创建空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在一个表中显示不同的列和非不同的列

Possible Duplicate:
Displaying distinct columns and non-distinct column in one table

我有3张桌子.一个是userinfo(可在其中找到Name),然后是logs(用于登录详细信息)和evaluation(用于对活动进行用户评估).它们通过字段attendee_id连接.

I have 3 tables. One is userinfo (which where you can find Name), then logs for login details and evaluation for user evaluation of the activity. They are connected by the field attendee_id.

当我加入他们时,它会为我提供以下输出:

When I joined them it gives me this output:

我想要的是这样的输出:

What I want is to have an output like this:

当我使用GROUP BY Name时,每组仅返回一行,而不返回其他数据.

When I use GROUP BY Name it returned only one row for each and not returning other data.

推荐答案

可以这样做.在此示例中,我对$rows数组进行了硬编码,但是您可以将其替换为数据库中的行数组.

It can be done like this. In this example I have hard coded the $rows array, but you can replace that with your array of rows from the database.

<?php

$rows = array(
    array(
        'name' => 'Juan',
        'login' => '09:00:01',
        'evaluation' => 'Yes'
    ),
    array(
        'name' => 'Juan',
        'login' => '09:00:02',
        'evaluation' => 'Yes'
    ),
    array(
        'name' => 'Juan',
        'login' => '09:00:03',
        'evaluation' => 'Yes'
    ),
    array(
        'name' => 'Jose',
        'login' => '09:00:04',
        'evaluation' => 'No'
    ),
    array(
        'name' => 'Jose',
        'login' => '09:00:05',
        'evaluation' => 'No'
    )
);

?>

<table>
<tr>
    <th>Name</th>
    <th>Login</th>
    <th>Evaluation</th>
</tr>
<?php
    $prevName = '';
    foreach($rows as $row):
        if($prevName == $row['name']) {
            $name = '';
        } else {
            $name = $prevName = $row['name'];
        }
?>
<tr>
    <td><?php echo htmlspecialchars($name); ?></td>
    <td><?php echo htmlspecialchars($row['login']); ?></td>
    <td><?php echo htmlspecialchars($row['evaluation']); ?></td>
</tr>

<?php endforeach; ?>
</table>

结果是:

这篇关于为重复行创建空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆