Next/Previous Article

admin

Administrator
Staff member
I am trying to use the next/previous article, with not a lot of luck.

Below is the entry I am using, however I think I have made an error near the while() part.

The database connects no problem, and the next/previous part is okay with page numbers.

Just the information I want displayed is not showing with the following error : Warning: Supplied argument is not a valid MySQL result resource in

I look forward to any suggestions....

Regards,

Donald.



<?php
$db = mysql_connect("****","*****", "*****");
mysql_select_db("******", $db);

$limit=20;
$numresults=mysql_query("select * from XXTitles order by Title");
$numrows=mysql_num_rows($numresults);

if (empty($offset)) {
$offset=1;
}

$result=mysql_query("select Title ".
"from XXTitles".
"order by Title limit $offset,$limit");

while ($data=mysql_fetch_array($result)) {
$title = $data["Title"];

echo ("$title<p>\n");
}
echo ("");


if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$prevoffset\">PREV</a> &nbsp; \n";
}


$pages=intval($numrows/$limit);


if ($numrows%$limit) {

$pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";
}


if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}

?>
 
Back
Top