make pagination wordpress admin panel

Solutions on MaxInterview for make pagination wordpress admin panel by the best coders in the world

showing results for - "make pagination wordpress admin panel"
Lenzo
11 Apr 2019
1// page parameter
2$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
3// Find total number of records
4
5$limit = 10; // number of rows in page
6$offset = ( $pagenum - 1 ) * $limit;
7$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM {$wpdb->prefix}table_name" );
8$num_of_pages = ceil( $total / $limit );
9
10// Give Limit
11$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}table_name LIMIT $offset, $limit" );
12
13
14// add this code where you want to add pagintaion
15$page_links = paginate_links( array(
16    'base' => add_query_arg( 'pagenum', '%#%' ),
17    'format' => '',
18    'prev_text' => __( '«', 'text-domain' ),
19    'next_text' => __( '»', 'text-domain' ),
20    'total' => $num_of_pages,
21    'current' => $pagenum
22) );
23
24if ( $page_links ) {
25    echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
26}
27