you original recordset had 2 conditions:
PageContentsID = (1 if there is no PageContentsID URL variable, if there is PageContentsID URL variable, that is used instead)
Permalink = (-1 if no Permalink URL variable, if there is a permalink URL variable, use that value instead.
so what was hapening was that when the prermlink URL variable existed, but not the PageContentsID url variable, the where clause became:
WHERE PageContentsID = 1 OR Permalink = <Permalink URTL Variable>
I'm pretty sure there is a record where PageContentsID = 1 so it was returning 2 results.
to correct that we add an additional condition so when there is the permalink URL variable but no PageContentsID url variable, the where clause becaomes:
WHERE (PageContentsID = 1 AND <permalinkUrlVariablevalue> = -1) OR Permalink = <permalinkUrlVariablevalue>
it was fine for the other contents because of the order of the 2 results returned.