One thing you could do is just hold the current article ID in a cookie or session variable, let's say $_SESSION['old_cur'] 😉
Now, on page creation, you'd want to execute one quick query:
SELECT articleID FROM `articles` ORDER BY ID ASC
Take that, and get it into an array. Since you know the current ID, just use [man]array_search/man to get the array key of the current ID. Then just decrement and increment the key to get the previous and next article ID 🙂
A short function would look something like:
function prevNext($id=null) {
if($id === null) return false;
$query = "SELECT articleID FROM `articles` ORDER BY articleID ASC";
$result = mysql_query($result);
if(!$result) return false;
while($row = mysql_fetch_array($result))
$res[] = $row['articleID'];
$currKey = array_search($id, $res);
if($currKey === false) return false;
$return['prev'] = $res[$currKey-1];
$return['next'] = $res[$currKey+1];
return $return;
}
And of course to speed things up you could store that returned array from the query in a SESSION or Cookie 😉