OMG, pagination question
Posted: Mon Dec 15, 2008 4:22 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I can't seem to figure why my page hyperlinks are not working in this code snippet. They render fine, but don't go anywhere.
Code:
thanks for any help.
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I can't seem to figure why my page hyperlinks are not working in this code snippet. They render fine, but don't go anywhere.
Code:
Code: Select all
<?php
$DBConnect = mysqli_connect("localhost", "root", "newpwd", "portfolio")
Or die("<p>Connection failed dude!</p>");
//checks if there's a page number, if not, sets it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
//counts the number of rows returned by query
$data = mysqli_query($DBConnect, "SELECT * FROM links") or die(mysqli_error($DBConnect));
$rows = mysqli_num_rows($data);
//number of results displayed per page
$page_rows = 5;
//page number of our last page
$last = ceil($rows / $page_rows);
//makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//sets the range to display query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//same query again with $max added into it
$data_p = mysqli_query($DBConnect, "SELECT * FROM links $max") or die(mysqli_error($DBConnect));
//display query results
echo "<table width='10%' border='1'>";
echo "<tr><th>Name</th><th>Description</th><th>Link</th></tr>";
while($info = mysqli_fetch_array($data_p, MYSQL_NUM))
{
//display name, desc, link
echo "<tr><td>{$info[0]}</td>";
echo "<td>{$info[1]}</td>";
echo "<td><a href='{$info[2]}'>Go There</a></td></tr>";
}
//shows user what page they are on and total number of pages
echo "<h2>--Page $pagenum of $last--</h2><p>";
echo "</table>";
// check if on page one, if not, generate links to first page and previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}
//checks if on last page and generates Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum + 1;
echo "<p><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}
mysqli_close($DBConnect);
?>~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: