1

I want show the rows of mysql table like this:

Today
Row1
Row2
....

Last day
Row1
Row2
...

Before last day
Row1
Row2
...

I have date column on my table: (id, message, date).

What is the method to show the result like the example i given ?

Here my approch in order to get the needed result:

$sql = $mysql->query("SELECT * FROM messages");
$array = array();
while($rows = mysql_fetch_array($sql)) {
  //Get proper date for array
  $key = date('Y-m-d', strtotime($rows["date"]));

  $arr[$key] = $rows["message"];

}
var_dump($array);

I want know if there a simple way to do it without array, or any other method.

My problem is not based on how to get Today, Yesterday ... But on how to show the structure in the example that i given, and write for each date (Today, Yesterday ...) with a specific rows into the while loop.

Mac Love
  • 13
  • 5
  • Possible duplicate of [PHP: How to check if a date is today, yesterday or tomorrow](http://stackoverflow.com/questions/25622370/php-how-to-check-if-a-date-is-today-yesterday-or-tomorrow) – Phiter Apr 06 '16 at 12:04
  • It's not same sorry. – Mac Love Apr 06 '16 at 12:06
  • It is if you tweak it a little. I'm showing you the path, you must do the rest of the job then ;) – Phiter Apr 06 '16 at 12:07
  • The problem is on the way to show it , for each rows they will have a title "Today, Yesterday ect...", and this with one mysql request, and not for each date i make new one since i have pagination system. – Mac Love Apr 06 '16 at 12:19
  • can you give some more day name in desired order ? for example today, last day, before last day,.......next which day ? – Jahangir Alam Apr 06 '16 at 12:46
  • Next will be the name of days (Monday, ...) and if up to one week, last week, and then by month, then by years. – Mac Love Apr 06 '16 at 12:57

0 Answers0