Results 1 to 4 of 4
Jan 9, 2011, 23:51 #1
How to paginate an article/news in php?
I want to paginate an article/new, that contains more than one page of content. I don't want to scroll down till end.
I want to check the length of the article and divide it into multiple pages and display at bottom of the page as next page links....
give me some idea about it.
Thanking you all...
Jan 10, 2011, 02:34 #2
- Join Date
- Jan 2007
- Christchurch, New Zealand
- 61 Post(s)
- 3 Thread(s)
Split the content across multiple pages, and place "prev page" and "next page" links along the top and bottom of the content. It's not that difficult.
Or, are you looking for an automatic way for it to be done for you?Programming Group Advisor
The 2013 SitePoint Awards - Nominate your heroes now!
Jan 10, 2011, 02:35 #3
Something like this:
$pageNum = isset($_GET['page']) ? (int) $_GET['page'] : 0;
$self = $_SERVER['PHP_SELF'];
// get the text from the file or form mysql database
$string = file_get_contents("D:\test.txt");
// quantity to display
$length = 3000;
// string length
$string_length = strlen($string);
// page number or quantity
$start = $pageNum * $length;
$endif = $string_length - $start;
// Returns the portion of string specified by the start and length parameters
$msg = substr($string, $start, $length);
echo wordwrap($msg, 100, "\n");
echo "\n<br />------<br />\n";
if ($pageNum > 0)
$page = $pageNum - 1;
echo '<br/><a href="' . $self . '?page=' . $page . '">prev page</a>';
if (($string_length > $length) and ($endif > $length))
$page = $pageNum + 1;
echo ' <a href="' . $self . '?page=' . $page . '">next page</a>';
}my mobile portal
Jan 10, 2011, 03:26 #4
Thanking you for your reply..pmw57.
How to automate this functionality..?
give me an example to understand...