0

I have this small section of code.

<?php foreach($last_activity as $activity) : ?>
<tr>
    <td><?= $activity['category'];?></td>
    <td><?= $activity['activity'];?></td>
    <td><?= $activity['datetime'];?></td>
    <td><?= $activity[''];?></td>
</tr>
<?php endforeach; ?>

This runs a loop populating table rows with data from query. What I want to be able to do providing possible this way...is in the final column in the row is calculate the difference between the datetime column in its present row with that of the row above.

is this possible (e.g by putting a snippet of php script in my final <td> column?

1 Answer 1

1

I suppose it can be done with something like this:

<?php $recent_datetime = null;
      foreach($last_activity as $activity): ?>
<tr>
    <td><?=$activity['category'];?></td>
    <td><?=$activity['activity'];?></td>
    <td><?=$activity['datetime'];?></td>
    <td><?= ($recent_datetime 
              ? $activity['datetime'] - $recent_datetime 
              : $activity['datetime'] );
         ?></td>
</tr>
<?php $recent_datetime = $activity['datetime']; endforeach; ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.