It's all php code. What I gave you should work pretty much as-is except that I didn't give you code for the page links (or prev/next) in the first post (it's in this one).
The first part goes someplace at or near the top of your file:
How many items do you want on a page?
$itemsPerPage = 10;
$pagenum = 1; /* the default */
This gets the value of 'page' if it was passed to your program by someone clicking a paging link:
/* Page to display is being passed in the query string */
if(isset($_GET['page']))
{
$pagenum = $_GET['page'];
}
You should check that it's a number and not someone trying to hack your database with a sql injection attack - I haven't included that code here.
This next part uses the requested page number and the number of items you want on a page and calculates the number of the first item to get from the database:
$offset = ($pagenum - 1) * $itemsPerPage;
You need to know how many pages you have so get the total # of rows and divide by the # of items you will show on a page:
Code:
$result = mysql_query("Select count(*) as numrows from news where live = '1'");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPages = ceil($numrows / $itemsPerPage);
(There's a more elegant way to do that, but this will work).
The "LIMIT ..." that I added to your query says to get the # of items you want to display per page, starting with the one we calculated in the last step.
The code below will display a simple "previous" or "next" link if there is a previous and/or next page to display:
Code:
$self = $_SERVER['PHP_SELF'];
if ($pagenum > 1) {
$page = $pagenum - 1;
print("<a href=\"" . $self . "?page=" . $page . "> Previous</a>ย ");
}
if ($pagenum < $maxPages) {
$page = $pagenum + 1;
print("<a href=\"" . $self . "?page=" . $page . ">Nextย </a>");
}
Gotta get back to my real work, but that should do the trick.