[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

Display post from correct month and year

I have a blog where you can select to view post from a particular year and month. When you click on the date in the archive list the URL sends the variables over like this...

archive.php?month=March&year=2012

I'm just not sure how to display them on the results page?

The date is stored in the database in date format in the eventdate column.

I basically need a query that says...

Show posts from latestnews where the year and month match those in the eventdate column of the databse.
Screen-shot-2012-04-05-at-14.13..png
Screen-shot-2012-04-05-at-16.35..png
0
BrighteyesDesign
Asked:
BrighteyesDesign
  • 2
1 Solution
 
Ray PaseurCommented:
The month and year will arrive in $_GET.  This will create a date range that runs from the first of the month to the end of the month.  Then you just use that in your WHERE clause.

See: http://www.laprbass.com/RAY_temp_brighteyesdesign.php?month=March&year=2012
<?php // RAY_temp_brighteyesdesign.php
error_reporting(E_ALL);

date_default_timezone_set('America/Chicago');

$alpha = date('c', strtotime($_GET["month"] . ' 1, ' . $_GET["year"]));
$omega = date('c', strtotime($_GET["month"] . ' ' . date('t', strtotime($alpha)) . ', ' . $_GET["year"]));
$where = " WHERE eventdate BETWEEN '$alpha' AND '$omega' ";
var_dump($where);

Open in new window

0
 
BrighteyesDesignAuthor Commented:
Perfect, thanks for that
0
 
Ray PaseurCommented:
'nada ;-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now