Problem Number 2
I implemented a 'Previous article Next article' feature at the top of each article page which provides an easy means to quickly navigate to another article.
This is the code currently in place:
PHP Code:
# previous and next article links
$nextone = $artid+1;
$chknextonequery = $DB_site->query("SELECT articles_articleid FROM " . TABLE_PREFIX . "articles_article WHERE articles_articleid=$nextone");
if($DB_site->num_rows($chknextonequery)>0)
{
$nextarticle = 1;
}
else
{
$nextarticle = 0;
}
$previousone = $artid-1;
$chkpreonequery = $DB_site->query("SELECT articles_articleid FROM " . TABLE_PREFIX . "articles_article WHERE articles_articleid=$previousone");
if($DB_site->num_rows($chkpreonequery)>0)
{
$prearticle = 1;
}
else
{
$prearticle = 0;
}
The template where it appears :
Code:
<span class="smallfont" style="float:$stylevar[right]">
<if condition="$prearticle==1">
<a href="articles.php?$session[sessionurl]action=viewarticle&artid=$previousone">< Previous Article</a></if>
<if condition="$nextarticle==1 && $prearticle==1">
|
</if>
<if condition="$nextarticle==1">
<a href="articles.php?$session[sessionurl]action=viewarticle&artid=$nextone">Next Article ></a></if>
</span>
Now this code works fine,
BUT it assumes that all the rows in the database for articles are present in running order. eg. articleid=1,2,3,4....,100.. It presents a problem when there is a missing articleid in between. for eg. articleid=1,2,3,5,8,10,...,100...
How can I change things to make this work ?
Also if possible combine queries ?