Danny620 Posted November 27, 2012 Share Posted November 27, 2012 my code below works fine however the last record has a new header see screenshoot <?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> Quote Link to comment https://forums.phpfreaks.com/topic/271261-grouping-date-not-working/ Share on other sites More sharing options...
akphidelt2007 Posted November 27, 2012 Share Posted November 27, 2012 (edited) 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 November 27, 2012 by akphidelt2007 Quote Link to comment https://forums.phpfreaks.com/topic/271261-grouping-date-not-working/#findComment-1395656 Share on other sites More sharing options...
Danny620 Posted November 27, 2012 Author Share Posted November 27, 2012 that did not work at all Quote Link to comment https://forums.phpfreaks.com/topic/271261-grouping-date-not-working/#findComment-1395678 Share on other sites More sharing options...
Danny620 Posted November 27, 2012 Author Share Posted November 27, 2012 sorry my bad it was right Quote Link to comment https://forums.phpfreaks.com/topic/271261-grouping-date-not-working/#findComment-1395680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.