Creating 2 diary pages with future and past events ... How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DeMolen
Forum Newbie
Posts: 2
Joined: Fri Oct 31, 2008 7:09 am

Creating 2 diary pages with future and past events ... How?

Post by DeMolen »

Dear Forum,

I'd be very grateful for any advice/assistance with the following problem:

Using a database of events with each event indexed using a date format eg. 20091031, I want to pull all events previous to today's date into one page (past diary) and all events from today's date into a second page (future diary). In this way an online diary will automatically update itself on the webpage once an event has passed.

Is this possible ... and how?

I'm using the following to select from the database:

Code: Select all

$sql = "SELECT * FROM diary ORDER BY dateindex DESC";
is there a way of adding to this code to the effect ...
'WHERE dateindex =< TODAY'

(dateindex is the DB field where all entries are formatted - 20091031)

Many thanks in advance for any bright ideas.

8)
zephyr750
Forum Newbie
Posts: 6
Joined: Sat Nov 01, 2008 8:05 am

Re: Creating 2 diary pages with future and past events ... How?

Post by zephyr750 »

I can't see why you couldn't use the php date(); function to create a "today" var. You may have to do two queries but that shouldn't be a problem.

Off the top of my head, try something like-

$today = date("Ymd");

then use the $today var in your query as you suggested ie.

$sql = "SELECT * FROM diary WHERE dateindex < $today ORDER BY dateindex DESC";

I'm only making a stab here, just yo be sure, I'd recommend looking up date(); in the php manual. That said, I think the above will give you what youi need......
DeMolen
Forum Newbie
Posts: 2
Joined: Fri Oct 31, 2008 7:09 am

Re: Creating 2 diary pages with future and past events ... How?

Post by DeMolen »

Works like a dream .... many thanks!!
Post Reply