Jump to content

Recommended Posts

my code below works fine however the last record has a new header

 

see screenshoot

 

screen.jpg

 

<?php

  $last_date = substr($all_status[0]['dr'], 0, -6);
  $date = substr($all_status[0]['dr'], 0, -6);

  foreach($all_status as $status){ ?>

  <?php

  if($last_date == $date){

	 $date = substr($status['dr'], 0, -6);

	 echo '<tr><th colspan="6" style="text-align:center; background-color:#CBF09E">' .  $date . '';

		   if($last_date == date('F d, Y')){ echo ' - Today'; }

	  echo '</th></tr>';

	 }else{

	 $last_date = substr($status['dr'], 0, -6);

	 }

  ?>

  <?php $status_message = substr(strip_tags($status['status_message'], ''), 0, 44) . '...'; ?>

   <tr>
   <td>...</td>
   <td><?php echo ($status['sent'] == '1') ? '<i class="icon-ok" title="Successfully Sent"></i>' : '<i class="icon-time" title="Not Yet Posted"></i>' ?></td>
   <td><?php echo ($status['success'] == '1') ? '<i class="icon-ok" title="Successfully Posted"></i>' : '<i class="icon-remove" title="Failed To Post"></i>' ?></td>
   <td><?php echo $status_message; ?></td>
   <td><?php echo $status['dr']; ?></td>
   <td>
   <a data-keyboard="true" data-backdrop="true" class="btn small edit" href="#">Edit</a>
   <a class="btn btn-danger" data-keyboard="true" data-backdrop="true" href="<?php echo BASE_LOGGEDIN_URL . 'delete.php?item=3&id=' . $status['status_id'] . ''; ?>">Delete</a></td>
   </tr>

   <?php } ?>

   </tbody>
   </table>

Link to comment
https://forums.phpfreaks.com/topic/271261-grouping-date-not-working/
Share on other sites

Your logic is a little wrong there.

 

$last_date = false;
$date = '';

foreach($all_status as $status){ ?>

<?php
$date = substr($status['dr'], 0, -6);
if($last_date != $date){

 //no reason for this line here
 //$date = substr($status['dr'], 0, -6);

 echo '<tr><th colspan="6" style="text-align:center; background-color:#CBF09E">' . $date . '';

 if($date == date('F d, Y')){ echo ' - Today'; }

 echo '</th></tr>';

 $last_date = $date;
}

Edited by akphidelt2007
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.