Breaking table on multiple pages

0

I'm creating a Web application that displayed two equal sized tables However, both have about 100 rows each, I would like to display only 25 rows from each table and to see the rest of the table would have those subsequent pages: 1, 2, 3, 4 ...

All I did until agr was just with php, mysql, css and html. would you need javascript, jquery or others?

Thank you

    
asked by anonymous 14.09.2017 / 18:48

2 answers

0

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

To retrieve only part of the MySQL results, use LIMIT in your query. Example:

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

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

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

I hope I have helped.

    
14.09.2017 / 19:01
1

There is a plugin that is called data-tables, which in my opinion is the best it gives you various options for tables, search for table data etc. eg:

I think you can use it by adding these tags here in your code but for a better understanding I suggest you view the link documentation.

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script><scriptsrc="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>
    
17.09.2017 / 05:49