Question

This is my second question (so far) this week. My first one achieved a successful solution so I thought this one could also get lucky. I want to layout/design the returns my query outputted me in this way:

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

Here is my php codes...

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>";
}
?>

So far, this outputs a tabular form report which is not what I really want. I've heard this "group" but I really need to have a good starter-idea to get it going.

Was it helpful?

Solution

Make a $date variable in your function and then on every iteration compare it to the current rows' date like so:

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>";
}

Updated from OPs screenshot

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>";
}

Based on what you're showing in your screenshot, it looks like that might fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top