If you got the WHOLE table back for the DB you could simply set aside a variables for prev/next and retrieve TWO records at a time... something like
Code:
$prev=$next=false;
while ($thisRow = mysql_fetch_assoc($result)){
$next=mysql_fetch_assoc($result);
if ($prev){ //Call your output foo: 'prev' link code //}
//Call your output 'current link' link code goes here//
if ($next){ //Call your output 'next' link code goes here //}
$prev=thisRow;
}
if ($next){
//Call your output foo: 'prev' link code, but this time send $thisRow as an argument //
//Call your output 'current link', but this time send $next;
}
voila.. this will scale anyway way you want it and you can arrange the order you get your results via your mySQL statement!
Of course, I don't understand why one would retrieve a whole table for a specific article. You could use a couple of mySQL queries ( possibly one , but I didn't want to start explain JOINS etc, when I myself rarely use them) .
for example here am sorting by alphabetically ( around a chosen article ID=19 )
Code:
SELECT * FROM `article_test` WHERE `title`<=(SELECT `title` FROM `article_test` WHERE `articleID`=19) ORDER BY `title` DESC limit 2
This gives your previous and current article...
Code:
SELECT * FROM `article_test` WHERE `title`>(SELECT `title` FROM `article_test` WHERE `articleID`=19) ORDER BY `title` ASC limit 2
and this gives you your next. The beauty of this method is it conserves resources, and its scalable. Wanna confuse users by presenting links to 5 previous articles and 10 following articles ... change the limit on the corresponding mySQL query. You can order change the ordering method by changing the SORT BY and the column which is selected inside the parenthesis (these two must be the same) .
It also has the added advantage of giving you convenient falses. That is the LAST entry will return 'false' on the NEXT query, and you will only get ONE entry ( the article itself) if your target article is the first article. These could be used to skip echoing back/forth button when they dont apply.
Anyway, I hope that helps.
Bookmarks