I'm creating a site with several articles. On the main page of this site I am creating section that shows you a preview of the articles and allows you go through them using a next and previous button. I found some example code designed for use with search results and am trying to adapt it my use. Instead of the prev and next links going to another page of results I want it to show the details of one row in the table and the links go to the prev and next row. I tested my query but when i put it into my php code it shows one page only and does not show any of my field data. Also the prev button is showing up even though it only detects one page. Here is the code I have so far. Any help you can provide is appreciated.
<?php
include 'config.php';
include 'opendb.php';
$limit=12; // rows to return
$numresults=mysql_query("select * from htarticles where archived=0 order by date desc");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
// get results
$result=mysql_query("select id,title,date,picname,summary,archived ".
"from htarticles where archived=0 ".
"order by date desc limit $offset,$limit");
// now you can display the results returned
while ($data = mysql_fetch_array($result)) {
// code to display results
echo '<center><table><tr><td>'.$result['title'].'</td></tr>
<tr><td>'.$result['date'].'</td></tr>
<tr><td>'.$result['pic'].'</td></tr>
<tr><td>'.$result['summary'].'</td></tr>
</table></center>';
}
// next we need to do the links to other results
if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
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";
}
?>