Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802

    inserimento di una classe pager

    salve a tutti , io con le classi , non ho dimestichezza , e siccome che mi serviva mettere una classe per lo smistamento dei dati estratti dal database ,
    ne ho scaricato una dal sito phpclasses.org .

    Io i dati li estraggo tramite una funzione , poi richiamando la funzione nel files dove c ' e il template con un foreach prelevo le arie chiavi, che a sua volta stamperanno il valore..

    ho provato in tanti modi ad applicare la classe , ma! se con il require_once richiamo nuovamente la classe mi da un errore fatal errore , adesso qual cuno mi potrebbe aiutare a capire ? il files dove c'è il template si chiama adminstaff.php , e li richiamo la funzione che estrae i dati,
    Codice PHP:

    function GetStaff()
    {
      global 
    $dbcore;
      global 
    $settings ;
      
      
    $sql mysql_query("select t. *  , gs. id_groups ,gs. nome_group from tech t  left join grouptech gs  on  t. groupid = gs. id_groups  order by t. staffid asc ") or die(mysql_error());
      
    $return = array();
      while (
    $row mysql_fetch_assoc($sql))
      {
        
    $return[] = $row;
      }
     return 
    $return;  

    nella pagina del template richiamando la funzione faccio
    Codice PHP:
    if (GetStaff()) 
    {
    $staff GetStaff();
    foreach(
    $staff as $tech){

    echo
    'QUIC E LA TABELLA CON I DATI' .$tech['nome'];
    }

    adesso dovrei implementare la classe......

    io la posto postandola cosi come l ho scaricata magari sarà utile a qual' cuno
    files esempio.php
    Codice PHP:
        //pager example
        
    include('class.pager.php');
        
    $total 128//this value should arrive from some database query, like "select count(id) from table_you_want_to_page" 
        
    $perpage 15//number of results to be shown per page
        
    $query_string "class.pager.example.php?"// current file.. 
        
    $pager = new pager($total$perpage$query_string); //building a pager
        
    echo "Pager example: Dividing {$pager->num_results} results into {$pager->page_list_size} pages showing {$pager->per_page} results per page

    "
    ;      
        
    $pg $pager->page//getting active page 
        
    echo "
    Active page " 
    $pg;
        echo 
    "

     Page list: "
    ;
        echo 
    $pager->getButPrev($pg); // get PREVIOUS button
        
    if($pager->getButPrev($pg)) echo $pager->separator//show a default seperator between PREVIOUS button and page list IF previous button is visible
        
    $range 4//set the range of page button list
        
    echo $pager->getButList($range); //display page buttons.. 1 2 3 4 5 etc
        
    if($pager->getButNext($pg)) echo $pager->separator//show a default seperator between page list and NEXT button IF next button is visible
        
    echo $pager->getButNext($pg); //get NEXT button
        
    echo "
    "
    ;
        echo 
    $pager->getRangeInfo(); // print "showing results x - y of z" 
        //some design tuning!
        
    $pager->but_prev "<a href=\"{query_string}&page={page}\">[b]&lt;&lt; ({page})[/b]</a>";
        
    $pager->but_next "<a href=\"{query_string}&page={page}\">[b]({page}) &gt;&gt;[/b]</a>";
        
    $pager->but_page "<a href=\"{query_string}&page={page}\">[Page: {page}]</a>";
        
    $pager->but_page_this "[Active page: {page}]";
        
    $pager->separator ".";
        
    $pager->range_display "You see results: {from} to {to} out of {total}";
        
    //now redraw..
        
    echo "

     Retuned Page list: "
    ;
        echo 
    $pager->getButPrev($pg);
        if(
    $pager->getButPrev($pg)) echo $pager->separator
        echo 
    $pager->getButList(6); 
        if(
    $pager->getButNext($pg)) echo $pager->separator
        echo 
    $pager->getButNext($pg); 
        echo 
    "
    "
    ;    
        echo 
    $pager->getRangeInfo();
        echo 
    "

    Extra info:

    "
    ;
        for(
    $i 1$i <= $pager->page_list_size$i++){
            echo 
    "Page " $i;
            echo 
    " -> Offset in db query: ";
            echo 
    $pager->getPageFrom($i);
            echo 
    "
    "
    ;
        }    
        
        
    //so, if you are in page 4, you should request results in database limited from $pager->getPageFrom(4), and running for $pager->page_size in length.. 
    e questa e la classe : class.pager.php
    Codice PHP:
        /**
        * Pager class
        * For doing the page-related math and generating page links (prev 1 2 3 4 5 next etc. ).
        *
        * @package Pager
        * @author spyefex <tomas@netatbiz.com>
        * @version 1.0
        * @copyright (c)2004, Net@Biz
        */    

        
    class pager {
            
    /**
            * Number of results to show per one page
            * @var int 
            */    
            
    var $per_page;
            
            
    /**
            * Currently active page
            * @var int 
            */            
            
    var $page;
            
            
    /**
            * Page text in query string
            * @var string 
            */            
            
    var $page_identifier;        
            
            
    /**
            * NEXT button html code template 
            * "{query_string}" and "{page}" will be automatically replaced by the appropriate values 
            * @var string
            */            
            
    var $but_next "<a href=\"{query_string}&page={page}\">next</a>";

            
    /**
            * PREVIOUS button html code template
            * "{query_string}" and "{page}" will be automatically replaced by the appropriate values  
            * @var string
            */            
            
    var $but_prev "<a href=\"{query_string}&page={page}\">prev</a>";
            
            
    /**
            * Page ( ie.: 1, 2, 3, or 4, etc. ) button html code template 
            * "{query_string}" and "{page}" will be automatically replaced by the appropriate values 
            * @var string
            */                    
            
    var $but_page "<a href=\"{query_string}&page={page}\">{page}</a>";
            
            
    /**
            * Currently active page button html code template
            * "{query_string}" and "{page}" will be automatically replaced by the appropriate values  
            * @var string
            */                    
            
    var $but_page_this "[b]{page}[/b]";
            
            
    /**
            * Separator template 
            * Will be included among page buttons in page list   
            * @var string
            */                    
            
    var $separator " - ";
            
            
    /**
            * Range display template
            * "{from}", "{to}" and "{total}" will be automatically replaced by the appropriate values 
            * @var string
            */                    
            
    var $range_display "Showing results {from} - {to} of {total} ";        
            
            
    /**
            * Total number of results 
            * @var int
            */            
            
    var $num_results;
            
            
    /**
            * Number of pages currently available 
            * @var int
            */            
            
    var $page_list_size;
                    
            
    /**
            * Initial query string for use in button links 
            * Including "file.php?" (Ie.: "index.php?location=heaven")  
            * @var string
            */            
            
    var $query_string;
            
            
    /**
            * Pager initialization
            *
            * @param int $num_results total number of results ( you should get this from database before constructing the pager object )         
            * @param int $per_page number of results to display in one page 
            * @param string $query_string initial query string ( if you are using this pager to display search results, $query_string should arrive dynamically according to search query )
            * @param string $page_id page identifier variable in query string (ie.: "pg");
            */            
            
    function pager($num_results$per_page 10$query_string ''$page_id "page") {
                
    $this->page = isset( $_REQUEST[$page_id] )? $_REQUEST[$page_id] : 1;
                
    $this->page_identifier $page_id;
                
    $this->per_page $per_page;
                
    $this->num_results $num_results;
                
    $this->query_string $query_string;
                
    $this->page_list_size = @ceil$num_results $per_page );
            }
            
            
    /**
            * Gets the result offset for a page.
            * NOTICE: If you want to use this function to
            * show the logically correct value for output in html (Ie.: "showing results 1 - 10"), 
            * you should increase the result of this function by 1 (because in real life results 
            * start from 1, not from 0)  
            *
            * @param int $page the page you want to get the offset for
            * @returns int         
            */            
            
    function getPageFrom($page) {
                if(
    $page <= 0) return 0;
                if(
    $page $this->page_list_size) return 0;
                
    $result = ($page-1) * $this->per_page;
                
    $result = ($result >= $this->num_results) ? ($this->num_results 1) : $result;
                return 
    $result;
            }
            
            
    /**
            * Gets the tail value of results shown in a page. 
            * NOTICE: Do NOT use the results of 
            * this function in database query, it's for outputting the range only.
            * (Ie.: "showing results 1 - 10")
            *
            * @param int $page the page you want to get the tail for
            * @returns int         
            */            
            
    function getPageTo($page) {
                if(
    $page <= 0) return 0;
                if(
    $page $this->page_list_size) return 0;
                
    $result = ($page-1) * $this->per_page $this->per_page;
                
    $result = ($result >= $this->num_results) ? $this->num_results $result;
                return 
    $result;
            }    
            
            
    /**
            * Generates the NEXT button html code from the predefined template 
            * (check initial vars for more information)
            *
            * @param int $page the page you want to get the NEXT button for ( usually the active page )
            * @returns string
            */            
            
    function getButNext($page) {
                
    $page++;
                if(
    $page $this->page_list_size) return "";
                if(
    $page 1) return "";
                
    $temp ereg_replace("{query_string}"$this->query_string$this->but_next);
                
    $result ereg_replace("{page}", (string)$page$temp);
                return 
    $result;
            }

            
    /**
            * Generates the PREVIOUS button html code from the predefined template 
            * (check initial vars for more information)
            *
            * @param int $page the page you want to get the PREVIOUS button for ( usually the active page )
            * @returns string
            */        
            
    function getButPrev($page) {
                
    $page--;
                if(
    $page 1) return "";
                if(
    $page $this->page_list_size) return "";
                
    $temp ereg_replace("{query_string}"$this->query_string$this->but_prev);
                
    $result ereg_replace("{page}", (string)$page$temp);
                return 
    $result;
            }        
                
            
    /**
            * Generates the PAGE button html code from the predefined templates 
            * (check initial vars for more information)
            *
            * @param int $page the page you want to get the PAGE button for
            * @returns string
            */                    
            
    function getButPage($page) {
                if(
    $page 1) return "";
                if(
    $page $this->page_list_size) return "";
                
    $source = ($page == $this->page) ? $this->but_page_this $this->but_page;
                
    $temp ereg_replace("{query_string}"$this->query_string$source);
                
    $result ereg_replace("{page}", (string)$page$temp);
                return 
    $result;            
            }
            
            
    /**
            * Generates the Google style PAGE button list html code from the predefined templates 
            * (ie.: "1 - 2 - 3 - 4 - 5", check initial vars for more information)
            *
            * @param int $range number of page buttons to be shown before and after tbe current page 
            * @returns string
            */            
            
    function getButList($range 9) {
                
    $range++;
                unset(
    $result);
                for(
    $i = ($this->page $range); $i <= ($this->page $range); $i++) {
                    if(
    $this->page $range) {
                        
    $result .= $this->getButPage($i);
                        if (
    $i == $range) break;
                    }
                    else 
    $result .= $this->getButPage($i);
                    if(
    $this->getButPage($i+1) && $result && $i $this->page $range
                        
    $result .= $this->separator;
                }
                return 
    $result;
            }
            
            
    /**
            * Generates the result range information text from the predefined template 
            * (ie.: "Displaying 1 - 3 of 24", check initial vars for more information)
            *
            * @returns string
            */                
            
    function getRangeInfo() {
                
    $from $this->getPageFrom($this->page) + 1;
                
    $to $this->getPageTo($this->page);
                
    $temp ereg_replace("{from}", (string)$from$this->range_display);
                
    $temp ereg_replace("{to}", (string)$to$temp);
                
    $result ereg_replace("{total}", (string)$this->num_results$temp);
                return 
    $result;
            }
            
        
        } 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    ragazzi mi potreste aiutare sempre naturalmente perfavore help
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    buon giorno a tutti , ragazzi mi dareste una mano?
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    ragazzi mi potreste dedicare cinque minuti
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    comunque grazie ugualmente
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    sono riuscito , a fare apparire i numeri della paginazione , però mi da questo errore la classe
    codice:
    Notice: Undefined variable: result in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\classi\pagerclass\class.pager.php on line 205
    inoltre mi cambia paina, ma non mi associa i valori del database ho messo nella select limit $perpage l errore che mi da e questo :
    Codice PHP:
    $result .= $this->getButPage($i); 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    sembra che io me la canto e me la suono da solo
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    ragazzi mi potrste aiutare help
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  9. #9
    non si capisce bene qual'è il problema, però ad intuizione non dovresti scrivere:
    Codice PHP:
    $query_string "adminstaff.php"// current file.. 
    ???

  10. #10
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    ma i valori dal database come li dovrei estrarre con limit?
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.