Hello! Help please, let's say there is a displayable news from the database consisting of, say, 1050 words, how to make sure that the news itself has page pagination (let's say 100 words per page) Here is the news output code:

<?php $res=mysql_query("SELECT * FROM `news` ORDER BY `id` DESC"); while($myrow=mysql_fetch_array($res)) { echo "<b><a class=title>".$myrow['title']."</a></b>"; echo "<a class=title_d>".$myrow['date_news']."</a><br><hr>"; if(isset($_GET['full']) && $_GET['full']==$myrow['id']) { echo "<div class=scroll><a class=mess>".$myrow['fullnews']."<br><br></a></div>"; echo "<a href=books.php>Скрыть</a><hr><br>"; } else { echo "<a class=mess>".$myrow['shortnews']."<br><br></a>"; echo "<a href=books.php?full=".$myrow['id']." class=button_full>Читать полностью</a><br><br><br>"; } } ?> 
  • We tried in php to break the line into spaces (if you wish, you can further process some special cases, but I think this is not particularly necessary) and print the first 100 words, then 100 words from the remaining ...? - Arnial

1 answer 1

Well, the answer lies at the heart of your question. You need to write a script that will process each page of the "news" separately. Those. respond to a request of type news/newsname/3 . In this script, you simply make a request to the database with the condition of limitation on the length of the content (100 words for example).

For MySQL, there are functions like this:

string LEFT( str string, len integer) . Returns the len of the first characters from the string str. Supports multibyte characters.

string SUBSTRING(str string FROM pos integer FOR len integer)

Returns a substring of the string str of len characters from the position pos. Supports multibyte characters.

  • LEFT will divide by characters, but need by words. - Arnial
  • The closest thing is SUBSTRING_INDEX but for the pages farther from the first, you will still have to cut out the previous part of the line, which in my opinion is already a SQL perch. - Arnial
  • Well, cutting into words is already a separate piece of code that should process. @Arnial agrees - it will be more difficult there. Therefore, the solution gradually develops into a division into blocks at the php level than at the MySQL level. - alexoander