Hi, i have a sql problem; I have some records ordered by date, and using PHP i can view the contents of an item in detail in my browser. However, i need a previous and next link to be able to jump quickly to other items.
However, since some of my items have the same date i have been having problems with selecting these previous and next items.
Here is a sample Database output :
SQL code to generate this :
Code:
SELECT * FROM jokes WHERE categoryID = '$categoryID' ORDER BY date DESC, title ASC LIMIT $start, $number
Holiday Dinner Oct 29th
Just Married Oct 26th
The geography Oct 26th
Top 10 slogans Oct 26th
Pregnant Oct 25th
Temptation Oct 25th
Next Item SQL =
Code:
SELECT title FROM items WHERE date <= '$date' AND categoryID = $category AND itemID != $itemID order by date desc, title asc limit 1
Previous Item SQL =
Code:
SELECT title FROM items wHERE date >= '$date' AND categoryID = $category AND itemID != $itemID order by date asc, title desc LIMIT 1
the $.. are variables, collected from the item the user is looking at.
When i look at an item in detail, here are the previous and next item suggestions:
Previous = Newer item
Next = Older item
holiday dinner:
NEXT -> just married
PREVIOUS -> /
just married
NEXT -> The geography
PREVIOUS -> top 10 slogans INCORRECT
The geography
PREVIOUS -> top 10 slogans INCORRECT
NEXT -> just married INCORRECT
top 10 slogans
PREVIOUS -> the geography
NEXT -> just married INCORRECT
pregnant
PREVIOUS -> tempation INCORRECT
NEXT -> temptation
Does anyone know how I can fix this? I'm using date at the moment, don't think datetime would make a difference, because i still want them grouped by day/month and then title.
Thank you very much