Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Query database for previous dated event

Please help me find my way!

4:46 am on Jul 7, 2011 (gmt 0)

New User

5+ Year Member

joined:June 18, 2011
posts: 3
votes: 0

Ok so here is the deal:

I have a page that displays details for (event A). at the end of the details I want to check if there is an event occurring before event A's date. If there is I want to display a link to event B but I can't figure out how to do this.

This is what I have:

$prev_search = "SELECT title FROM events WHERE date < " . strtotime($event_data['date']);
$find_event = mysql_query($prev_search);
if (mysql_num_rows($find_event) != 0)
$prev_event = mysql_fetch_array( $find_event );
echo "<a class=\"readmore\" href=\"" . $base_url . "events/" . str_replace(" ", "_", $prev_event['title']) . "\"> Previous Event</a>";


Which works in only displaying the "previous" button if there is an event before this one, but i want it to only display the previous date. you get what Im saying?
12:00 pm on July 7, 2011 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
votes: 11

Mike, welcome to the forums

Try: SELECT MAX(date),title
Instead of: SELECT title

This will invariably return one row with the 'largest' timestamp.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members