Question: How would I go about not displaying the message timestamp for incoming/outgoing messages if they occur during the same 5 minutes as the previous message. How iMessage does it. I have it set up to where every message has a timestamp now but having a hard time figuring out how to limit them. How would I go about setting some kind of filter? 

MySQL

```
$query = "SELECT *
FROM messages A
JOIN profiles B ON
B.user = A.auth
JOIN lastmessage C ON
B.user = C.user
WHERE A.recip ='$view'
ORDER BY A.time DESC
";

```

PHP 

```
    $result = queryMysql($query);
    $num    = $result->num_rows;
    $delayInSeconds = 300; // 5 minutes

    for ($j = 0 ; $j < $num ; ++$j)
    {
      if ($row['time'] >= strtotime("today") && $row['lastMessageTime'] < $row['time'] - $delayInSeconds)
    echo "<strong>Today</strong>" . date(' g:i A', $row['time']);
     $row['lastMessageTime'] = $row['time'];

  if ($row['time'] >= strtotime("yesterday") && $row['lastMessageTime'] < $row['time'] - $delayInSeconds)
    echo  "<strong>Yesterday</strong>". date(' g:i A', $row['time']);
    $row['lastMessageTime'] = $row['time'];

  if ($row['time'] >= strtotime("yesterday + 3,601") && $row['lastMessageTime'] < $row['time'] - $delayInSeconds)
    echo date('D, M d, g:i A', $row['time']);
    $row['lastMessageTime'] = $row['time'];

```

Answer: 
Presumably you're looping through the messages?

Just keep track of a variable for the last printed timestamp and only display the current messages time if it is >5 minutes later.

eg something like (pseudo-ish)

```
$lastMessageTime = 0; // epoch
$delayInSeconds = 300; // 5 minutes

foreach($messages as $message)
{
    //Print message (with whatever formatting  you want)
    echo $message->message;

    // Print time, if last time displayed was over 5 minutes ago
    if($lastMessageTime < $message->time - $delayInSeconds)
    {
        //More than 5 minutes ago, print time
        echo date('D, M d, g:i A', $message->time);
        $lastMessageTime = $messsage->time;
    }

}

```
I've never used iMessage but it seems you're looking for something like this (pseudo code):

```
$last_timestamp = '';

foreach(...){

  if($last_timestamp !== $this_timestamp){
    echo $this_timestamp;
    $last_timestamp = $this_timestamp;
  }

}

```

This way, you'll only print the timestamp whenever it is different from the previous one.

*Edit*: to round per 5 minutes, you could also do something like this instead:

```
  if($last_timestamp < $this_timestamp - 5 minutes)

```