1

这是我本周的第二个问题(到目前为止)。我的第一个实现了成功的解决方案,所以我认为这个也可以很幸运。我想布局/设计我的查询以这种方式输出的返回:

date 1    |    id       |     time     |     updated by    |     Status Update
          |     1       |     04:06    |       user1       |   this is a remark
          |     2       |     05:05    |       user2       |   this is again a remark
          |     3       |     05:08    |       user1       |   this is another remark
          |     4       |     07:09    |       user3       |   and this one also
date 2    |    id       |     time     |     updated by    |     Status Update
          |     5       |     04:06    |       user3       |   this is a remark for day 2
          |     6       |     05:05    |       user3       |   this is again a remark for day 2
date 3    |    id       |     time     |     updated by    |     Status Update
          |     7       |     04:06    |       user1       |   this is a remark
          |     8       |     05:05    |       user2       |   this is again a remark
          |     9       |     05:08    |       user2       |   this is another remark
          |     10      |     07:09    |       user3       |   and this one also

这是我的php代码...

mysql declaration here
{
echo "<table border='0' align=center class='tablefont'>
<tr class='colheadbg'>
<th>Date</th>
<th>ID</th>
<th>Time</th>
<th>Updated by</th>
<th>Status Update</th>
</tr>";

while($info = mysql_fetch_array( $data ))
{
$id_num=$id_num + 1;
echo "<tr>
<td>".$info['date']."</td>
<td>$id_num</td>
<td>".$info['time']."</td>
<td>".$info['user']."</td>
<td>".$info['remarks']."</td>";
echo "</tr>";
}
echo "</table>";
}
?>

到目前为止,这会输出一个表格形式的报告,这不是我真正想要的。我听说过这个“团体”,但我真的需要有一个好的入门想法才能让它继续下去。

4

1 回答 1

1

在您的函数中创建一个$date变量,然后在每次迭代时将其与当前行的日期进行比较,如下所示:

var $date = "";

while($info = mysql_fetch_array( $data )) {
    $id_num=$id_num + 1;
    echo "<tr>";
    if ($date==$info['date']) {
        echo "<td>".$info['date']."</td>
        <td>$id_num</td>
        <td>".$info['time']."</td>
        <td>".$info['user']."</td>
        <td>".$info['remarks']."</td>";
    }
    else {
         $date=$info['date']; //set it for the new date first
        //do your row magic
    }
    echo "</tr>";
}

从 OP 截图更新

var $date = "";

while ($info = mysql_fetch_array( $data )) {
    $id_num++;

    echo "<tr>";

    if ($date == $info['date']) {
        echo "<td>"./**nothing**/."</td>";
        echo "<td>$id_num</td>
        <td>{$info['time']}</td>
        <td>{$info['user']}</td>
        <td>{$info['remarks']}</td>";
    }
    else {
        $date = $info['date']; //set it for the new date first
        echo "<td>$date</td>
        <td>$id_num</td>
        <td>{$info['time']}</td>
        <td>{$info['user']}</td>
        <td>{$info['remarks']}</td>";
    }

    echo "</tr>";
}

根据您在屏幕截图中显示的内容,看起来这可能会解决它。

于 2013-03-21T05:44:40.750 回答