I am creating a web app where if a user clicks on Link called \"WEEK\", the page shows up all the posts which were submitted in that week. There\'s also an option to view all th
Well, by slightly modifying your code, you could realize the WEEK- and MONTH-Problem using SQL!
Regarding to: MySQL-Documentation, this might be the solution for you:
SELECT *
FROM posts
WHERE YEARWEEK(post_date) = YEARWEEK(NOW())
Second one may be a bit more complicated:
SELECT *
FROM posts
WHERE YEAR(post_date) = YEAR(NOW())
AND MONTH(post_date) = MONTH(NOW())
I hope, i could help you.
There are several MySQL functions that do things like this for you
SELECT * FROM posts
WHERE
WEEK(post_date) = WEEK(CURDATE())
AND
MONTH(post_date) = MONTH(CURDATE())
What about this?
if($_GET['when'] == "today") {
$query = "SELECT * FROM posts WHERE DATE(post_date) = CURDATE()";
} else if ($_GET['when'] == "week") {
$query = "SELECT * FROM posts WHERE post_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK)";
} else if ($_GET['when'] == "month") {
$query = "SELECT * FROM posts WHERE post_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)";
}
$result = mysql_query($query);