tags:

views:

69

answers:

2

I am using the pager class (from pear) in PHP. I am not sure if I am using it right, but I downloaded some code from Internet where I can include a pager class and call the pager function.. This is how I am calling the Pager function in my php page...

require_once('pager/Pager.php');
 $pager_options = array(
        'mode'       => 'Sliding',
        'append'    => false,
        'perPage'    => 30,
        'delta'      => 4,
        'fileName'  => '/temp-%d.htm',
        'currentPage' => $pagenum,        
        'totalItems' => $rows,
        'curPageLinkClassName' => 'active',
        'separator' => '',
        'nextImg' => '<strong>Next</strong> &raquo;',
        'prevImg' => '&laquo; <strong>Previous</strong>',
        'spacesBeforeSeparator' => 0,
        'spacesAfterSeparator' => 0,
        'clearIfVoid' => true
        );
        $pager = Pager::factory($pager_options);
        echo '<div align="center" id="pagination">' .  $pager->links . '</div>';

Now, it works fine, but my problem is, for the first page the link would be temp-1.htm, but I want it as temp.htm or temp/index.htm... For other pages, temp-2.htm, temp-3.htm is fine..

Is there any work around? Thanks in advance...

A: 
echo '<div align="center" id="pagination">',
     str_replace('temp-1.htm', 'temp.htm', (string) $pager->links),
     '</div>';
ntd
A: 

Not very familiar with Pager, however you could have something like this

require_once('pager/Pager.php');

 $filename = ($pagenum == 1) ? 'temp.htm' : '/temp-%d.htm';

 $pager_options = array(
        'mode'       => 'Sliding',
        'append'    => false,
        'perPage'    => 30,
        'delta'      => 4,
        'fileName'  => $filename,
        'currentPage' => $pagenum,        
        'totalItems' => $rows,
        'curPageLinkClassName' => 'active',
        'separator' => '',
        'nextImg' => '<strong>Next</strong> &raquo;',
        'prevImg' => '&laquo; <strong>Previous</strong>',
        'spacesBeforeSeparator' => 0,
        'spacesAfterSeparator' => 0,
        'clearIfVoid' => true
        );
        $pager = Pager::factory($pager_options);
        echo '<div align="center" id="pagination">' .  $pager->links . '</div>';
falomir