Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805

    inserire una classe in una query

    buon giorno a tutti apro questa discussione nuovamente in quanto dal mio pannello di controllo ho cancellato la precedente discussione ,
    avrei bisognio di un vostro aiuto , ho scaricato una classe per la paginazione , però on so come assegniare il limite per pagina alla query, spero di avere un vostro aiuto posto l ' esempio
    Codice PHP:
    //pager example
    $conn mysql_connect("localhost""root""maurizio");
    $db mysql_select_db("supp");
    include(
    'class.pager.php');
    $array mysql_query("SELECT * FROM tech where staffid = staffid ");
    $result mysql_num_rows($array);
        
    $num_results $result //this value should arrive from some database query, like "select count(id) from table_you_want_to_page" 
        
    $per_page 1//number of results to be shown per page
        
    $query_string "class.pager.example.php?"// current file.. 
        
    $pager = new pager($num_results$per_page$query_string); //building a pager
        
    $sql mysql_query("SELECT * FROM tech  limit {$pager->num_results},{$pager->page_list_size} ,{$pager->per_page}");
        while(
    $row mysql_fetch_assoc($sql) )
        {
        echo 
    $row['nome'].'-'$row['cognome'].'-'$row['username'].'
    '
    ;
        }
    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 "

    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 posto anche la casse

    Codice PHP:
        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 $_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;
            }
            
        
        } 
    grazie a tutti anticipatamente
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ho fatto cosi ,
    Codice PHP:
    $sql mysql_query("SELECT * FROM tech  limit   {$pager->num_results}  , {$pager->per_page}"); 
    se tolgo uno dei due oggetti vunziona , mi da se lascio
    Codice PHP:
    limit   {$pager->num_results
    il numero totale degli utenti presenti ,se invece lascio solamente
    Codice PHP:
    {$pager->per_page
    mi appare il numero di utenti inserito nella variabile
    Codice PHP:
    $per_page 1

    qual' cuno di voi mi potrebbe dare una mano , e molto importante
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    dinuovo sera ho rimodificato la query ma nessuna soluzione
    Codice PHP:
        $pager = new pager($num_results$per_page$query_string); //building a pager
        
    $sql mysql_query("SELECT * FROM tech  ".$pager->getLimit."".$pager->pager($num_results$per_page$query_string)."");
        echo 
    $pager->pager($num_results$per_page$query_string);
        
        while(
    $row mysql_fetch_assoc($sql) )
        {
        echo 
    $row['nome'].'-'$row['cognome'].'-'$row['username'].'
    '
    ;
        } 
    mi date una mano perfavore help disperatamente
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ragazzi salve a tutti come posso estrarre i valori della query mi date una mano grazie infinite


    i record totali nel db sono 2
    e da estrarre per pagina ne deve estrarre 1

    cosi mi vede che le pagine sono 2, pero mi estrae dal database tutte e due record perche??
    Codice PHP:
        $num_results =//this value should arrive from some database query, like "select count(id) from table_you_want_to_page" 
        
    $per_page 1//number of results to be shown per page
        
    $query_string "class.pager.example.php?"// current file.. 
        
    $pager = new pager($num_results$per_page$query_string); //building a pager
        
    $sql mysql_query("SELECT * FROM tech pg".$pager->pager($num_results$per_page$query_string)."");
        echo 
    $pager->pager($num_results$per_page$query_string);



        while(
    $row mysql_fetch_assoc($sql) )
        {
        echo 
    $row['nome'].'-'$row['cognome'].'-'$row['username'].'
    '
    ;
        } 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    buongiorno a tutti nessuno propio riesce a darmi una mano !
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ciao a tutti cortesemente ragazzi datemi una mano sono bloccato da questa classe
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    comunque mi sto rispondendo da solo chi sa perche ?
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ragazzi perche nessuno di voi non mi da una mano ?
    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.