homepage Welcome to WebmasterWorld Guest from 54.242.18.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Query database for previous dated event
Please help me find my way!
MikeElmore




msg:4336174
 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?

 

brotherhood of LAN




msg:4336310
 12:00 pm on Jul 7, 2011 (gmt 0)

Mike, welcome to the forums

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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved