admin管理员组

文章数量:1312662

I Want to display pagination in one of my page of plugin ,created by me..

I am grateful if someone can help I want pagination in back end(in admin) not in front end, and print reservation as pdf. this my function how can I add pagination and print as pdf?

    function friday_reservations(){ 

<div class="wrap">
    <h1>Reservations</h1>
    <table class="wp-list-table widefat striped">
        <thead>
            <tr>
                <th class="manage-column">ID</th>
                <th class="manage-column">Gebet</th>
                <th class="manage-column">Genre</th>
                <th class="manage-column">Name</th>
                <th class="manage-column">Last Name</th>
                <th class="manage-column">E-mail</th>
                <th class="manage-column">Phone</th>
                <th class="manage-column">Number</th>
                <th class="manage-column">Delete</th>
            
            
            </tr>
        </thead>
        <tbody>
        <?php
            global $wpdb;
            $table = $wpdb->prefix . 'fridyreservation';
            $reservations = $wpdb->get_results("SELECT * FROM $table", ARRAY_A);
           
            foreach($reservations as $reservation): ?>

                <tr>
                    <td><?php echo $reservation['id']; ?></td>
                    <td><?php echo $reservation['predigt']; ?></td>
                    <td><?php echo $reservation['genre']; ?></td>
                    <td><?php echo $reservation['fname']; ?></td>
                    <td><?php echo $reservation['lname']; ?></td>
                    <td><?php echo $reservation['email']; ?></td>
                    <td><?php echo $reservation['phone']; ?></td>
                    <td><?php echo $reservation['pnumber']; ?></td>
                    <td>
                        <a href="#" class="remove_reservation" data-reservation="<?php echo $reservation['id']; ?>">Remove</a>
                    </td>
                
                </tr>


            <?php endforeach;
        ?>
        </tbody>
    </table>
</div>

I Want to display pagination in one of my page of plugin ,created by me..

I am grateful if someone can help I want pagination in back end(in admin) not in front end, and print reservation as pdf. this my function how can I add pagination and print as pdf?

    function friday_reservations(){ 

<div class="wrap">
    <h1>Reservations</h1>
    <table class="wp-list-table widefat striped">
        <thead>
            <tr>
                <th class="manage-column">ID</th>
                <th class="manage-column">Gebet</th>
                <th class="manage-column">Genre</th>
                <th class="manage-column">Name</th>
                <th class="manage-column">Last Name</th>
                <th class="manage-column">E-mail</th>
                <th class="manage-column">Phone</th>
                <th class="manage-column">Number</th>
                <th class="manage-column">Delete</th>
            
            
            </tr>
        </thead>
        <tbody>
        <?php
            global $wpdb;
            $table = $wpdb->prefix . 'fridyreservation';
            $reservations = $wpdb->get_results("SELECT * FROM $table", ARRAY_A);
           
            foreach($reservations as $reservation): ?>

                <tr>
                    <td><?php echo $reservation['id']; ?></td>
                    <td><?php echo $reservation['predigt']; ?></td>
                    <td><?php echo $reservation['genre']; ?></td>
                    <td><?php echo $reservation['fname']; ?></td>
                    <td><?php echo $reservation['lname']; ?></td>
                    <td><?php echo $reservation['email']; ?></td>
                    <td><?php echo $reservation['phone']; ?></td>
                    <td><?php echo $reservation['pnumber']; ?></td>
                    <td>
                        <a href="#" class="remove_reservation" data-reservation="<?php echo $reservation['id']; ?>">Remove</a>
                    </td>
                
                </tr>


            <?php endforeach;
        ?>
        </tbody>
    </table>
</div>
Share Improve this question edited Dec 15, 2020 at 17:07 Rup 4,4004 gold badges29 silver badges29 bronze badges asked Dec 14, 2020 at 22:30 AyariAyari 1 3
  • I don't think there's a simple way to do either: I'm not sure you can hook your separate table into WordPress's existing pagination, and I don't believe there's an easy way to print as a PDF unless you can find a PHP package to do that for you. – Rup Commented Dec 15, 2020 at 17:09
  • To implement pagination yourself you'll want to count the number of rows in the table and then select pages worth using LIMIT and OFFSET (see MySQL SELECT documentation) – Rup Commented Dec 15, 2020 at 17:11
  • ok that's help for beginner like me thank you i try – Ayari Commented Dec 15, 2020 at 18:54
Add a comment  | 

1 Answer 1

Reset to default 0

hi i find the solution by :

https://stackoverflow/questions/5322266/add-pagination-in-wordpress-admin-in-my-own-customized-plugin

$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
$limit = 10; // number of rows in page
$offset = ( $pagenum - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM {$wpdb->prefix}table_name" `);
$num_of_pages = ceil( $total / $limit );`

i change this to my database:

$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}table_name LIMIT $offset, $limit" );
$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'prev_text' => __( '&laquo;', 'text-domain' ),
'next_text' => __( '&raquo;', 'text-domain' ),
'total' => $num_of_pages,
'current' => $pagenum
) );

if ( $page_links ) {
echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
}

thats all . just now i have to find how can i delete all the rservation?

本文标签: phpDisplay pagination in reservation Plugin and and Print table as pdf