ive built a little news system and i want to show older news e.g news.php?month=3 will show the last 3 months news etc..
i cant seem to get the date comparision working though. entry's in the n_date field in the database are in the format of d/m/y
// work out months
$month = date("m");
$year = date("Y");
$day = date("d");
$this_m = date( "d/m/y", mktime(0, 0, 0, $month - 1, 0, $year) ) ;
$three_m = date( "d/m/y", mktime(0, 0, 0, $month - 3, 0, $year) ) ;
$six_m = date( "d/m/y", mktime(0, 0, 0, $month - 6, 0, $year) ) ;
$twelve_m = date( "d/m/y", mktime(0, 0, 0, $month - 12, 0, $year) ) ;
// Month Switch //
switch ($month) {
case "1"; $query = "SELECT * FROM News WHERE n_date > $this_m ORDER BY n_date DESC"; // The Query
break;
case "3"; $query = "SELECT * FROM News WHERE n_date > $three_m ORDER BY n_date DESC"; // The Query
break;
case "6"; $query = "SELECT * FROM News WHERE n_date > $six_m ORDER BY n_date DESC"; // The Query
break;
case "12"; $query = "SELECT * FROM News WHERE n_date > $twelve_m ORDER BY n_date DESC"; // The Query
break;
default: $query = "SELECT * FROM News ORDER BY n_date DESC LIMIT 5"; // The Query
}
$query_result = mysql_query ($query) or die('SQL Query Failed - Getting News');
for($i = 0; $i < 100; $i++){
for ($count = 1; $row = mysql_fetch_assoc ($query_result);++$count) {
display results here..
}