Monday, November 29, 2010

Neighbours are backwards.

I am getting neighbours based on created date, my id field is not sequential so since they are ordered and displayed in order of created date I get the neighbours the same way.

 

I see the 2 neighbouring results (debug them also) and they are reversed. Next should be Prev and Prev should be Next, at the beginning or end they end at the correct place except for the direction.

 

Here is SQL output:

 

SELECT `Post`.`created`, `Post`.`id`, `Post`.`title` FROM `Posts` AS `Post` WHERE `Post`.`status` = 0 AND `Post`.`private` <= 1  AND `Post`.`created` < '2010-11-29 11:23:05' ORDER BY `Post`.`created` DESC LIMIT 1

SELECT `Post`.`created`, `Post`.`id`, `Post`.`title` FROM `Posts` AS `Post` WHERE `Post`.`status` = 0 AND `Post`.`private` <= 1 AND `Post`.`created` >= '2010-11-29 11:22:20' AND `Post`.`created` != '2010-11-29 11:23:05' ORDER BY `Post`.`created` ASC LIMIT 2

 

So get Post with date less than '2010-11-29 11:23:05' which is the time of the Post being viewed so get the Post created right before this one so if I click on the newest Post Prev should be empty but its actually showing the next record 2nd oldest in the DB and Next is empty.

 

Anyone seen this before?

 

Is it just because im using time rather than an actual ID?

 

Thanks,

 

Dave

 

 

No comments: