Page 1 of 1

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

Posted: Fri Oct 31, 2008 7:24 am
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)

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

Posted: Sat Nov 01, 2008 2:20 pm
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......

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

Posted: Wed Nov 05, 2008 3:31 am
by DeMolen
Works like a dream .... many thanks!!