Ok, what I'm trying to do is have next and prev buttons to navigate through a mysql database sorted by date. Currently, the code I wrote does this, but gets stuck on duplicate dates.
$Next = mysql_query("SELECT * FROM $logbook WHERE Date>='$Date' AND ID!='$ID' ORDER BY Date LIMIT 1");
$Prev = mysql_query("SELECT * FROM $logbook WHERE Date<='$Date' AND ID!='$ID' ORDER BY Date DESC LIMIT 1");
When there are duplicate dates, this code returns the same id for both $Next and $Prev. I also tried:
$Next = mysql_query("SELECT * FROM $logbook WHERE Date>='$Date' AND ID!='$ID' ORDER BY Date, ID LIMIT 1");
$Prev = mysql_query("SELECT * FROM $logbook WHERE Date<='$Date' AND ID!='$ID' ORDER BY Date, ID DESC LIMIT 1");
This always returns the earliest Date instead of the previous one for $Prev, so I tried:
$Next = mysql_query("SELECT * FROM $logbook WHERE Date>='$Date' AND ID!='$ID' ORDER BY Date, ID LIMIT 1");
$Prev = mysql_query("SELECT * FROM $logbook WHERE Date<='$Date' AND ID!='$ID' ORDER BY Date DESC, ID ASC LIMIT 1");
The output from this query is the same as the first. The reason I can't simply sort by ID (which is an auto-incrementing field) is that entries may be post dated (Date is not a timestamp). Therefore, an entry with id 888 may need to come before an entry with id 877 because it has an earlier date. So what I need help figuring out is how to deal with duplicate dates.