Solved

Display post from correct month and year

Posted on 2012-04-05
3
384 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
  • 2
3 Comments
 
LVL 108

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 108

Expert Comment

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

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now