1

これは今週の私の2番目の質問です(これまでのところ)。私の最初のものは成功した解決策を達成したので、これも幸運になるかもしれないと思いました。クエリが出力したリターンを次のようにレイアウト/設計したいと思います。

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 に答える