Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    40
    Thanks
    0
    Thanked 1 Time in 1 Post

    Create pagination foreach loop

    Hello,

    I'm using a WordPress plugin (Footbal Pool plugin). It is a very complicated script but I want to add pagination to my ranking output...

    I managed to create this:

    PHP Code:
        public function print_pool_ranking$league$user$ranking_id FOOTBALLPOOL_RANKING_DEFAULT ) {
            
    $output '';
            
            
    $rows $this->get_pool_ranking$league$ranking_id );
            
    $ranking $users = array();
            if ( 
    count$rows ) > ) {
                
    // there are results in the database, so get the ranking
                
    foreach ( $rows as $row ) {
                    
    $ranking[] = $row;
                    
    $users[] = $row['user_id'];
                }
            } else {
                
    // no results, show a list of users
                
    $rows $this->get_users$league );
                if ( 
    count$rows ) > ) {
                    
    $output .= '<p>' __'No results yet. Below is a list of all users.'FOOTBALLPOOL_TEXT_DOMAIN ) . '</p>';
                    foreach ( 
    $rows as $row ) {
                        
    $ranking[] = $row;
                        
    $users[] = $row['user_id'];
                    }
                } else {
                    
    $output .= '<p>'__'No users have registered for this pool (yet).'FOOTBALLPOOL_TEXT_DOMAIN ) . '</p>';
                }
            }
            
            if ( 
    count$ranking ) > ) {
                
    // get number of predictions per user if option is set
                
    $show_num_predictions = ( Football_Pool_Utils::get_fp_option'show_num_predictions_in_ranking' ) == );
                if ( 
    $show_num_predictions ) {
                    
    $predictions $this->get_prediction_count_per_user$users$ranking_id );
                }
                
                
    $userpage Football_Pool::get_page_link'user' );
                
    $all_user_view = ( $league == FOOTBALLPOOL_LEAGUE_ALL && $this->has_leagues );
                
    $i 1;
                
                
    $output .= '<table class="standen">';
                if ( 
    $show_num_predictions ) {
                    
    $output .= sprintf'<tr>
                                            <th>positie</th>
                                            <th>%s</th>
                                            <th>%s</th>
                                            <th>%s</th>
                                            %s</tr>'
                                        
    __'user'FOOTBALLPOOL_TEXT_DOMAIN )
                                        , 
    __'predictions'FOOTBALLPOOL_TEXT_DOMAIN )
                                        , 
    __'points'FOOTBALLPOOL_TEXT_DOMAIN )
                                        , ( 
    $all_user_view '<th></th>' '' )
                                );
                }
                
    $count_records 1;
                foreach ( 
    $ranking as $row ) {
                    
    $opgeteld $count_records++;
                    
    $class = ( $i != 'even' 'odd' );
                    if ( 
    $all_user_view $class .= ' league-' $row['league_id'];
                    if ( 
    $row['user_id'] == $user $class .= ' currentuser';
                    if ( 
    $show_num_predictions ) {
                        if ( 
    array_key_exists$row['user_id'], $predictions ) ) {
                            
    $num_predictions $predictions[$row['user_id']];
                        } else {
                            
    $num_predictions 0;
                        }
                        
    $num_predictions sprintf'<td>%d</td>'$num_predictions );
                    } else {
                        
    $num_predictions '';
                    }
                    
    $output .= sprintf'<tr class="%s"><td style="width:100px; text-align: center;">%d.</td>
                                        <td><a href="%s">%s%s</a>%s</td>
                                        %s<td>%d</td>%s
                                        </tr>'
    ,
                                    
    $class,
                                    
    $i++,
                                    
    esc_urladd_query_arg( array( 'user' => $row['user_id'] ), $userpage ) ),
                                    
    $this->get_avatar$row['user_id'], 'medium' ),
                                    
    $row['user_name'],
                                    
    Football_Pool::user_name$row['user_id'], 'label' ),
                                    
    $num_predictions,
                                    
    $row['points'],
                                    ( 
    $all_user_view $this->league_image$row['league_id'] ) : '' )
                                );
                    
    $output .= "\n";
                }
                
    $output .= '</table>';
            }
            print 
    $opgeteld;
            
    $pages 1;
            
    $totalpages $opgeteld/10;
                for (
    $i 0$i $totalpages$i++)
                    {
                        print 
    $pages++.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    }
            return 
    $output;
        } 
    This class is returning all the users and there rank in a table.

    I made a counter that counts all the records and creates numbers (pagination)

    How can I realise that those pages are clickable and that the first page only contains the first ten records.

    Page 1: 1-10
    Page 2: 11-20

    and so on...

    I really dont know how to realise this.

    The plugin has a pagination class allready but I dont know to use this... It is in the attachement.

    Regards

    Joep
    Attached Files Attached Files


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •