• Resolved marlene4us

    (@marlene4us)


    how make the paging this it?

    <?php
    global $wpdb;
    
    $result = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."mytable ORDER BY date_added DESC" );
    
    ?>
    <div class="wrap">
    
    	<table class="widefat">
    		<thead>
    			<th>User</th>
    			<th>IP</th>
    		</thead>
    		<tbody>
    		<?php foreach ( $notifications as $notification ) : ?>
    			<tr>
    				<td style="padding:5px;"><?php echo $result->user; ?></td>
    				<td style="padding:5px;"><?php echo $result->ip; ?></td>
    			</tr>
    		<?php endforeach;?>
    		</tbody>
    		<tfoot>
    			<th>User</th>
    			<th>IP</th>
    		</tfoot>
    	</table>
    	<p>&nbsp;</p>
      </form>
    </div>
    <?php
    }
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter marlene4us

    (@marlene4us)

    resolved, my contribution:

    <?php
    global $wpdb;
    
    $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
    $limit = 50;
    $offset = ( $pagenum - 1 ) * $limit;
    
    $results = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."mytable ORDER BY date_added DESC LIMIT $offset, $limit" );
    $total = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."mytable" );
    
    $num_of_pages = ceil( $total / $limit );
    $page_links = paginate_links( array(
    	'base' => add_query_arg( 'pagenum', '%#%' ),
    	'format' => '',
    	'prev_text' => __( '?', 'aag' ),
    	'next_text' => __( '?', 'aag' ),
    	'total' => $num_of_pages,
    	'current' => $pagenum
    ) );
    
    ?>
    <div class="wrap">
    
    	<table class="widefat">
    		<thead>
    			<th>#</th>
    			<th>User</th>
    			<th>IP</th>
    		</thead>
    		<tbody>
    		<?php
    		$id = $offset + 1;
    		foreach ( $results as $result ) : ?>
    			<tr>
    				<td style="padding:5px;"><?php echo $id; ?></td>
    				<td style="padding:5px;"><?php echo $result->user; ?></td>
    				<td style="padding:5px;"><?php echo $result->ip; ?></td>
    			</tr>
    		<?php endforeach;?>
    		</tbody>
    		<tfoot>
    			<tr>
    				<th>#</th>
    				<th>User</th>
    				<th>IP</th>
    			</tr>
    			<tr>
    				<th colspan='3'><?php if ( $page_links ) { echo $page_links; }?></th>
    			</tr>
    		</tfoot>
    	</table>
      </form>
    </div>
    <?php
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘I have a query that returns a large list, how make the paging this it?’ is closed to new replies.