Solved

Display post from correct month and year

Posted on 2012-04-05
3
439 Views
Last Modified: 2012-04-05
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
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37812537
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
 

Author Closing Comment

by:BrighteyesDesign
ID: 37812672
Perfect, thanks for that
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37812710
'nada ;-)
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question