Welcome to WebmasterWorld Guest from 54.161.255.61

Forum Moderators: open

Query database for previous dated event

Please help me find my way!

   
4:46 am on Jul 7, 2011 (gmt 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>";

}else{}


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 Jul 7, 2011 (gmt 0)

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



Mike, welcome to the forums

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

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

Featured Threads

Hot Threads This Week

Hot Threads This Month