Hey all. I have a simple Pagination script that I use to help create pages of old news articles. Right now the script works in the sense that it will display an article, get the number of pages based on the number of entries in the database, and produce the pagination links. But the fun stops there. Currently the database is small as this is a new project but there are roughly 7 archived posts. Unfortunately the script will only get the most recent article and display it. It will not iterate through the db and display all the articles as I need it to do. The code is below. Thanks in advance for any help!!
<?
if(isset($_GET['pageno'])){
$pageno = $_GET['pageno'];
}else{
$pageno = 1;
}
//Get the number of rows in the database
$query = 'SELECT count(*) FROM news';
$result = mysql_query($query);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
//Identify the number of the last page
$rows_per_page = 10;
$lastpage = ceil($numrows/$rows_per_page);
//Check to ensure that $pageno is between 1 and $lastpage
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
//Construct the LIMIT clause for the MySQL SELECT statement
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
//Perform the MySQL query
$query = "SELECT * FROM news ORDER BY article_id $limit";
$result = mysql_query($query);
?>
<td width="753" height="350" valign="top" bgcolor="#ffffff" colspan="5">
<div style="width:747px;height:350px;overflow:auto;">
<br><br>
<center>
<?
while($news = mysql_fetch_assoc($result)){
$id = $news['article_id'];
$name = $news['name'];
$added_by = $news['added_by'];
$date_added = $news['date_added'];
$stub = $news['stub'];
}
echo "<table align=center border=0 cellpadding=0 cellspacing=0 width=420>";
echo "<tr><td class='articlename' width=420 height=28 style=\"background-image: url('../images/bgrnd_nav.gif');\" valign=center> " .$name."</td></tr>";
echo "<tr><td class='articleauthor' width=420 height=28 valign=center style=\"background-image: url('../images/bgrnd_footer_boxes.gif');\"> Posted by: ".$added_by. " on ".$date_added."</td></tr>";
echo "<tr><td class='articlestub' width=420 valign=center><blockquote><br />".$stub. "... <a class=small href=/news/view-article.php?article_id=".$id.">more</a></blockquote></td></tr>";
echo "</table>";
echo "<br /><br />";
?>
<?
//Construct hyperlinks which allow the user to select previous pages.
if ($pageno == 1) {
echo " <b class=small> FIRST PREV </b>";
} else {
echo " <b><a class=small href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a></b> ";
$prevpage = $pageno-1;
echo " <b><a class=small href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a></b> ";
}
//Current position
echo " <b class=small><font color=#c000c0>( Page $pageno of $lastpage )</font></b> ";
//Construct hyperlinks which allow the user to select following pages.
if ($pageno == $lastpage) {
echo " <b class=small> NEXT LAST</b> ";
} else {
$nextpage = $pageno+1;
echo " <b><a class=small href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a></b> ";
echo " <b><a class=small href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a></b> ";
}
?>
</center>
</div>
</td>