PHP and Mysql Text Pagination

Asked

Viewed 82 times

-1

I have a large text with many characters and I need to make it stay in 5 pages with option NEXT PAGE and PREVIOUS PAGE.

I searched and I can not find any tutorial on the subject, someone can help me?

I need a different way of javascript that I found here. The code below is reduced for testing.

<?
include("config/config.php");

////////////////NOVO MYSQLI////////////////
$seleciona = "SELECT * FROM news_ind where id = '$idnoticias2'";
$result = $conecta->query($seleciona);
$ver = $result->fetch_array(MYSQLI_ASSOC);
////////////////NOVO MYSQLI////////////////

$noticia = $ver["noticia"];

?>


<? echo $noticia; ?>

  • I recommend reading this post: https://answall.com/questions/26303/como-fazer-pagina%C3%A7%C3%A3o-php-e-mysql

  • Can you verify the answer? Don’t forget to accept it if you are satisfied with it.

1 answer

0

The "page" can be made both in your database and in the code. Regardless of where it is made, the logic is the same.

The first step is to determine the font size of each page and this can be fixed in your code. The second step is to calculate the number of pages. The 3rd is to page and take the content from the current page.

Considering that pages have up to 100 characters and a text with 450 characters, it could be done:

$tam_pagina = 100;
$tam_texto = strlen($noticia); // ex: 450
$pagina_atual = 2; // iniciando em 0; neste caso vai até 4
$total_paginas = ceil($tam_texto / $tam_pagina);
$inicio_pagina = $pagina_atual * $tam_pagina;

$texto_pagina = substr($noticia, $inicio_pagina, $tam_pagina);

Caveat:

  • It is necessary to consider that the news has only texts (not already HTML or markdown, for example, because part of a marckup can be on one page and the other part on another page.

Alternatives:

  • You can create your own bookmark to define where content is divided into pages, allowing you to have markups on content (such as Wordpress’s "read more" - <!--more-->);
  • You can create a control in your table (or another table) indicating the contents of substring, allowing pages with different sizes, for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.