Divide text to pages?

A

Anonymous

Guest
How can I divide text from database into pages?

Like what some websites do to split articles into pages!

can anybody show me the way to do it?
 
Hi
I already searched but I will search again

do anyone have any tutorial about that?
it would be helpful :)

Thanks in advance
 
do you need pagination or do you need a tutorial on how articles in DB can be presented ?
 
do you need pagination or do you need a tutorial on how articles in DB can be presented ?

I need an explanation or tutorial to make a pagination for an article (Divide one long article into pages) :help:
 
I found a solution for that ...
It cut the article into parts but not a proper cut (it cuts the word from the middle sometimes)
How can I fix it?


Code:
<?php
if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 10; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 

////////////////////////////////////////////////

$text = "I need to make a pagination to this text without cutting the words but cutting from the spaces";
////////////////////////////////////////////////

echo substr($text, $from,$max_results); 

/////////////////////////
// Figure out the total number of chars : 
$total_results = strlen ($text);

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<center>Select a Page<br />"; 

// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> "; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"; 
} 
echo "</center>";

/////////////////

?>
 
I think this is not the proper way of displaying article in multiple pages.

In this way you have to do lots of file handling and even not sure that result will come accurate.

If I will be doing this then I assigned pages to the articles while adding article and accordingly design my database.
 
Alexei Thats what i also suggest but i think your answer is more explantory then mine.

:D :D
 
It seems my last solution
I will try what you have suggested guys
I was thinging about what you have suggested before but it is much work to do so I tried to find another way :(
 
why dont' you try this
from preg_split

Code:
<?php
// split the phrase by any number of commas or space characters,
// which include " ", \r, \t, \n and \f
$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
?>

i think this would be very useful
 
Back
Top