Why isn't my code displaying the links???
Posted: Mon Jul 24, 2006 8:11 pm
My code doesn't display the links to each page. Can someone please tell me why this is happening and how I can fix it? Thanks in advance.
Here is my code:
Here is my code:
Code: Select all
require "config2.php";
// how many rows to show per page
$rowsPerPage = 2;
// by default we show first page
$pageNum = 1;
// if $_GET['article_id'] defined, use it as page number
if(isset($_GET['article_id'])) {
$pageNum = $_GET['article_id'];
}
// counting the offset
$offset = ($pageNum > 1) ? ($pageNum - 1) * $rowsPerPage : $rowsPerPage;
$query = "SELECT * FROM items LIMIT $offset, $rowsPerPage";
if ($r = mysql_query ($query)) {
$str = "";
while ($row = mysql_fetch_array ($r)) {
$str .= '<p>'. $row['date_entered'] . '<br />' . $row['article_item'] . '<br />
<a href="modify_article.php?id="'. $_GET['article_id'] .'">Modify</a>
<a href="delete_article.php?id="'. $_GET['article_id'] .'">Delete</a>
</p>';
}
if($str==="") {
echo 'No entries to be displayed. <a href="add_an_article.php">Click here</a> to return to the main page.<br />';
} else {
echo $str;
}
}
// how many rows we have in database
$query = "SELECT COUNT(article_id) AS numrows FROM items";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['article_id'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
if ($pageNum > 1) {
$page = $pageNum - 1;
echo "<a href=\"$self?page=1&rowsPerPage=$rowsPerPage\">First Page</a> - ";
echo "<a href=\"$self?page=$page&rowsPerPage=$rowsPerPage\">Previous</a> - ";
} else {
echo "First Page - ";
echo "Previous - ";
}
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
echo $pageNum." of ".$maxPage." - ";
echo " <a href=\"$self?page=$page&rowsPerPage=$rowsPerPage\">Next</a> - ";
echo "<a href=\"$self?page=$maxPage&rowsPerPage=$rowsPerPage\">Final Page</a>";
} else {
$page = $pageNum + 1;
echo $pageNum." of ".$maxPage." - ";
echo " Next - ";
echo "Final Page";
}
// and close the database connection
mysql_close();