Code:
if($_GET['page']) { // Is the page defined?
$page = $_GET['page']; // Set page defined
} else {
$page = 1; // Default page is 1
}
$max = 1; // Max results on a page
$cur = (($page * $max) - $max); // Works out what results to show
$sql = "SELECT * FROM `users` ORDER BY `id` DESC LIMIT $cur, $max";
$result = mysql_query($sql) or die ('Error selecting users from the database!' .mysql_error());
$count_total = mysql_query("SELECT * FROM `users` "); // 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='.$prev.'">Previous</a>';
}
for($i == 1; $i <= $total_pages; $i++) // For each page number
if($page == $i) { // If page = current page
$curPage = '<b>'.$i.'</b>'; // Echo page in bold
} else {
$thePages = '<a href="?page='.$i.'">'.$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="?page='.$next.'">Next>></a>'; // Echo next page link
}
Then where you want the text at, add the following:
Code:
echo $prevTxt.$curPage.$thePages.$nextTxt;
Hope this helps.
Bookmarks