Breaking table into multiple pages

Asked

Viewed 809 times

0

I am creating a web application that displays two tables of equal sizes However, both have about 100 lines each, I would like only 25 rows of each table to be displayed and to see the rest of the table would have those subsequent pages: 1, 2, 3 ,4...

Everything I did up to agr was just php, mysql, css and html. would need javascript, Jquery or others?

Thank you

  • Look up Bootstrap Table, that’s exactly what you want, but it’s all kind of done. You only need to be familiar with Jquery (Java Script library).

  • I use the Datatables to do this, but you have to know Jquery.

  • This Datatables looks pretty easy, I’ll try for it.

2 answers

1

there is a plugin called data-Tables, which in my opinion is the best it gives you various options for tables, table data search etc ex: inserir a descrição da imagem aqui

I believe you can use by adding these tags here in your code but for better understanding I suggest you see the documentation https://datatables.net/

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>

0


You can split the table into different pages using php/mysql only.

To recover only part of Mysql results, use LIMIT in your query. Example:

SELECT * FROM tabela WHERE campo='valor' LIMIT 0,25

The above query will recover the first 25 lines of the query. To recover the next 25 entries, use LIMIT 25,25 (the first parameter is the offset, ie how many lines you want to "skip" while retrieving the results, and the second parameter is how many lines bring).

To jump from one page to another, the suggestion is to use a GET variable (variables that are in the page URL). So if your page is at the address www.exemplo.com.br/table.php, just create a link to the next page using www.exemplo.com.br/table.php? page=2, for example. To get the value of the variable in PHP just use $_GET['pagina'].

I hope I’ve helped.

  • Really this is a very interesting way to do, however, daily this table will be fed with new data, so the pages are not automatic are? By what I understood I would have to create several querys for each page.

  • No, it wouldn’t. The query would be the same every time, you would just pass the offset as a parameter to the query.

  • I was able to do it the way you said, thank you very much!

Browser other questions tagged

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