I am working on my PHP to fetch the dates from the mysql database. I want to set up the date in the correct order that start from today date to the previous date then fetch the data I want.
Here is the PHP:
try {
$stmt = $link->prepare("SELECT * FROM inbox LIMIT 10");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach($stmt->fetchAll() as $k=>$v) {
$received_date = $v['received_date'];
echo $received_date;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
It give me the output like this:
Fri, 31 Aug 2018 14:52:16 -0600
Mon, 13 Aug 2018 00:29:38 +0000 (UTC)
Mon, 13 Aug 2018 01:28:25 +0100
Mon, 3 Sep 2018 16:46:06 -0600
Mon, 3 Sep 2018 17:50:33 -0600
Fri, 7 Sep 2018 16:47:46 -0600
Fri, 7 Sep 2018 13:41:08 -0600
Tue, 4 Sep 2018 15:11:51 -0600
Tue, 11 Sep 2018 02:30:57 +0100
Tue, 11 Sep 2018 02:30:22 +0100
Here is what I want to achieve:
Tue, 11 Sep 2018 02:30:57 +0100
Tue, 11 Sep 2018 02:30:22 +0100
Fri, 7 Sep 2018 16:47:46 -0600
Fri, 7 Sep 2018 13:41:08 -0600
Tue, 4 Sep 2018 15:11:51 -0600
Mon, 3 Sep 2018 17:50:33 -0600
Mon, 3 Sep 2018 16:46:06 -0600
Fri, 31 Aug 2018 14:52:16 -0600
Mon, 13 Aug 2018 01:28:25 +0100
Mon, 13 Aug 2018 00:29:38 +0000 (UTC)
I have got no idea how I could set up the date in the correct order that start from today date then to the previous date and fetch the data I want. The column received_date
I am using are a text so I have stored them as a string in the database.
I want to set up the date in the correct order as I want to fetch the data from the today date to the previous date so I could output them in my page where I could use it to check for my emails.
Can you please show me an example how I could set up the date in the correct order that start today date to the previous dates that I could fetch the data at the same time?
EDIT: When I tried this:
$stmt = $link->prepare("SELECT * FROM inbox ORDER BY received_date DESC LIMIT 10");
It will give me this:
Wed, 31 Oct 2018 11:14:38 -0400
Wed, 29 Aug 2018 16:44:17 -0400
Wed, 27 Mar 2019 21:37:05 +0000
Wed, 27 Mar 2019 03:37:05 +0000
Wed, 26 Sep 2018 18:45:40 -0400
Wed, 24 Oct 2018 23:11:11 -0400
Wed, 24 Apr 2019 19:43:06 +0100
Wed, 24 Apr 2019 01:43:07 +0100
Wed, 22 Aug 2018 16:11:48 -0400
Wed, 19 Sep 2018 19:35:45 -0400
It should be:
Wed, 24 Apr 2019 19:43:06 +0100
Wed, 24 Apr 2019 01:43:07 +0100
Wed, 27 Mar 2019 21:37:05 +0000
Wed, 27 Mar 2019 03:37:05 +0000
Wed, 31 Oct 2018 11:14:38 -0400
Wed, 24 Oct 2018 23:11:11 -0400
Wed, 26 Sep 2018 18:45:40 -0400
Wed, 19 Sep 2018 19:35:45 -0400
Wed, 29 Aug 2018 16:44:17 -0400
Wed, 22 Aug 2018 16:11:48 -0400
Here is what I stored the strings in the database:
Wed, 31 Oct 2018 11:14:38 -0400
Wed, 29 Aug 2018 16:44:17 -0400
Wed, 27 Mar 2019 21:37:05 +0000
Wed, 27 Mar 2019 03:37:05 +0000
Wed, 26 Sep 2018 18:45:40 -0400
Wed, 24 Oct 2018 23:11:11 -0400
Wed, 24 Apr 2019 19:43:06 +0100
Wed, 24 Apr 2019 01:43:07 +0100
Wed, 22 Aug 2018 16:11:48 -0400
Wed, 19 Sep 2018 19:35:45 -0400