ok, I have been trying to get a pagination script running for a while now and can't seem to get it. Here is my code:
PHP Code:
function getLinkPage() {
// Pagination Script
if($_GET['page_num']) { // Is the page defined?
$page_num = $_GET['page_num']; // Set page defined
} else {
$page_num = 1; // Default page is 1
}
$max = 20; // Max results on a page
$cur = (($page * $max) - $max); // Works out what results to show
$count_total = mysql_query("SELECT * FROM links"); // Get data from database
$count_total = mysql_num_rows($count_total); // Count lines in database
$total_pages = ceil($count_total / $max); // Total results divided by max to display
if($page > 1) { // Is the page # more than one?
$prev = ($page - 1); // If yes, take one away from current page
$prevTxt = '<a href="?page_num='.$prev.'"><<Previous</a>';
}
$nav = ' ';
for($i == 1; $i <= $total_pages; $i++) // For each page number
if($page == $i) { // If page = current page
$nav .= '<b>'.$i.'</b>'; // Echo page in bold
} else {
$nav .= ' <a href="">'.$i.'</a> '; // Echo link to the page
}
if($page < $total_pages) { // Is there another page?
$next = ($page + 1); // If so, add 1 to current page
$nextTxt = '<a href="">Next>></a>'; // Echo next page link
}
Here is the code where I run the sql query:
PHP Code:
$max = 20; // Max results on a page
$cur = (($page_num * $max) - $max); // Works out what results to show
// Query to get links from database
$sql = "SELECT * FROM `links` ORDER BY `count` ASC LIMIT $cur,$max";
$result = mysql_query($sql) or die ('Error Getting Links! <br />' .mysql_error());
The error I get is this: "Error Getting Links!
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20,20' at line 1". Obviously it has something to do with my $cur,$max statement to limit the results. I am thinking that maybe it is not setting the page number to 1 and therefore multiplying 20 by 0 and subtracting 20, hence -20. Could the problem be that I also use ?page=whatever to get pages, not just page numbers? Thanks in advance
Bookmarks