again pagination / Help Please!

again pagination

i have code:


$xtpl→assign_file ( "FILE_RIGHT", 'templates/grid.html' );


class Customer extends fActiveRecord {


public static function findActive($sort_column, $sort_dir) {

$rows = fRecordSetbuildFromSQL(CLASS,"SELECT * FROM customers");

$page = fRequestget('page'); $limit = 10; $total_items = $rows→count(); //echo $total_items;

if( !isset($page) (is_numeric($page) == false) ) $page = 1; if ($page == 0) $page = 1; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_items/$limit); $lpm1 = $lastpage - 1; if($page) $set_limit = ($page - 1) * $limit; else $set_limit = 0; ## afisare paginare $pagina = ""; $txt_prev = "previous"; $txt_next = "next"; $alamat_pag = "index.php?"; $adjacents = 1;

require('paginare.php');


if (!in_array($sort_column, array('zip', 'city'))) { $sort_column = 'zip'; }

if (!in_array($sort_dir, array('asc', 'desc'))) { $sort_dir = 'desc'; }

return

fRecordSetbuildFromSQL(CLASS, "SELECT * FROM customers ORDER BY $sort_column $sort_dir LIMIT $set_limit, $limit");

}

}


//$pagination = Customer::pagination; //$xtpl→assign ( 'PAGINARE', $pagination);

// Set the users to be sortable by name or email, defaulting to name $sort = fCRUDgetSortColumn ( array ('zip', 'city') ); // Set the sorting to default to ascending $dir = fCRUDgetSortDirection ( 'asc' );

$xtpl→assign ('city_sort', fCRUDprintSortableColumn('city', 'Oras'));

fCRUDgetColumnClass('zip');

$customers = Customer::findActive($sort, $dir);


foreach ( $customers as $customer ) {

$customer_id = fRequestget('id');

$xtpl→assign ( 'rows', fCRUDgetRowClass($customer→getId(), $customer_id) ); $xtpl→assign ( 'nume', $customer→prepareFirstname () ); $xtpl→assign ( 'prenume', $customer→prepareLastname () ); $xtpl→assign ( 'strada', $customer→prepareStreet () ); $xtpl→assign ( 'zip_class', fCRUDgetColumnClass('zip')); $xtpl→assign ( 'zip', $customer→prepareZip () ); $xtpl→assign ( 'city_class', fCRUDgetColumnClass('city')); $xtpl→assign ( 'oras', $customer→prepareCity () ); $xtpl→assign ( 'id_tara', $customer→prepareCountryid () ); $xtpl→assign ( 'activ',fCRUDshowChecked($customer→prepareActiv (), 1) ); $xtpl→parse ( 'main.right.row' );

}




how can print variable $pagination outside the class? i use xtemplate and i want to parse: $xtpl→assign ( 'PAGINARE', $pagination);

pls somebody help me

  • Message #200

    hey man…. here is a little pagination class i wrote:

    <?php
     
    class Pagination {
     
        private function checkPageSet($page_number){
     
            // Check the page number
            if(!isset($page_number) || $page_number == 0 || $page_number > $last_page ) {
                $page_number = 1;
            }
        
        }
     
        public function currentlyDisplayed($records){
            // Get the requested page number
            $page_number = fRequest::get('page_number','integer');
            
            // Check the page number, not set or 0 then set to 1
            if(!isset($page_number) || $page_number == 0 ) {
                $page_number = 1;
            }
            
            // Get current #records, and the total # in the table
            $record_count = $records->count();
            $record_total = $records->count(TRUE);
            
            // Showing results $record_start to $record_end
            $record_end = ($page_number * PER_PAGE);
            
            // Correct the math on $record_end, it will be greater than the total # in db on the last page
            if ($record_end > $record_total) {
                $record_end = $record_total;
            }
            
            // Start record number based off PER_PAGE constant
            if($page_number > 1) {
                $record_start = (($page_number * PER_PAGE) + 1) - PER_PAGE;
            } else {
                $record_start = 1;
            }
            
            echo "<p>Showing results $record_start to $record_end of $record_total</p>";
            
        }
     
        public function create($page,$records) {
     
            $record_count = $records->count();
            $record_total = $records->count(TRUE);
     
            // Get the requested page number
            $page_number = fRequest::get('page_number','integer');
     
            // Last Page
            $last_page = ceil($record_total/PER_PAGE);
     
            // Check the page number
            if(!isset($page_number) || $page_number == 0 || $page_number > $last_page ) {
                $page_number = 1;
            }
     
            // Prev/Next pages
            $next_page = $page_number+1;
            $prev_page = $page_number-1;
     
            // Build the pages out
            echo "<div class='pages'>\n";
     
            // Previous Page
            if($page_number > 1){
                echo "<a href=\"/$page/".$prev_page."\" class=\"nextprev\">&#171; Previous</a>\n";
            } else {
                echo "<span class='nextprev'>&#171; Previous</span>\n";
            }
            
            // Loop
            for($i = 1;$i <= $last_page;$i++){
                if($i < 11) {
                    if($page_number == $i) {
                        echo "<span class=\"current\">".$page_number."</span>\n";
                    } else {
                        echo "<a href=\"/$page/".$i."\">".$i."</a>\n";
                    }
                }
            }
            
            // More than 10 pages
            if($last_page > 10) {
                echo "<span>&#0133;</span>\n";
                echo "<a href=\"/$page/".($last_page-1)."\">".($last_page-1)."</a>\n";
                echo "<a href=\"/$page/".$last_page."\">".$last_page."</a>\n";
            }
            
            // Next Page
            if($last_page == $page_number){
                echo "<span class='nextprev'>Next &#187;</span>\n";
            } else {
                echo "<a href=\"/$page/".$next_page."\" class=\"nextprev\">Next &#187;</a>\n";
            }
            
            // End it
            echo "</div>\n";
        
        }
     
    }
     
    ?>
    

    Say inside my Order.php class, I have this function:


    public static function getPage() {
            $page_number = fRequest::get('page_number','integer');
            return fRecordSet::build('Order',array(),array('order_id' => 'desc'),PER_PAGE,$page_number);
        }
    

    On the page I want to create the pagination, I call this stuff:

    // Pull in the records
    $orders = Order::getPage();
     
    // Call the pagination class
    $pagination = new Pagination();
    // Create 'Showing results $record_start to $record_end of $record_total'
    $pagination->currentlyDisplayed($orders);
     
    foreach($orders as $order){
         // display your records
    }
     
    // Create the page links
    $pagination->create($page,$orders);
    

    PER_PAGE is just an int constant for how many records you would like to display on a page.

    Hope that helps

    • Message #206

      tank u my friend with a little modification it was very useful for me.

      • Message #492

        out of curiosity, what changes did you make?