Visualizzazione dei risultati da 1 a 5 su 5

Discussione: classe per datagrid

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805

    classe per datagrid

    buongiorno ragazzi scusate avrei bisognio un a vostra mano , ho scaricato una classe dal sito phpclasses.org , e l ho modificata a secondo le mie necessita , ora la classe per il datagrid funziona , però se nel database e inseroito un link o un email , me la vede come semplice testo perche? posto la classe e in fase di modifiche
    Codice PHP:

    <?php
    class phpSortTable {

        
        
        var 
    $tableName;
        var 
    $urlKeyName;
        var 
    $tableKeyName;
        var 
    $editLink;
        var 
    $editTarget;
        var 
    $editWindowFormat;
        var 
    $deleteLink;
        var 
    $addLink;
        var 
    $addTarget;
        var 
    $addText;
        var 
    $editPromptMsg;
        var 
    $deletePromptMsg;
        var 
    $asc_img;
        var 
    $desc_img;
        var 
    $edit_img;
        var 
    $delete_img;
        var 
    $add_img;

        var 
    $cellpadding "" ;
        var 
    $cellspacing "" ;
        var 
    $tableborder "" ;
        var 
    $width "" ;
        var 
    $tbclass "" ;
        var 
    $style "" ;

        var 
    $columHeader = array();
        var 
    $columContent = array();
        var 
    $tableTitle = array();

        var 
    $defaultRowsNum;
        var 
    $imgFilePath;
        var 
    $cssFilePath;
        var 
    $emptyMsg;
        var 
    $columns;
        
        var 
    $selfLink;

        var 
    $urlVars;  # contains the application given urls vars

        /**
         * @var string total number of rows found in the query
         */
        
    var $totalRows;
        var 
    $shownRows;
        
        var 
    $colsNum;
        var 
    $rows;
        var 
    $begin;

        var 
    $sortby;


         function 
    __construct($connectionData$tableName) {
            
    $this->connectionData $connectionData;
            
    $this->tableName $tableName;
            
            
    /** 
             * * * * * * * * * * * * * * * * * 
             *         Vars Initialization
             * * * * * * * * * * * * * * * * *
             */
            
    $this->imgFilePath "phpSortTable/img/";
            
    $this->cssFilePath "phpSortTable/php_sort_table.css";
            
    $this->asc_img "asc.gif";
            
    $this->desc_img "desc.gif";
            
    $this->add_img "add.gif";
            
    $this->delete_img "delete.gif";
            
    $this->edit_img "edit.gif";
            
            
    $this->defaultRowsNum 5;
            
    $this->emptyMsg "No data to be shown.";
            
    $this->editWindowFormat "";
        }
        
        
        
        
        
          function 
    phpSortTable($connectionData$tableName) {
            
    $this->connectionData $connectionData;
            
    $this->tableName $tableName;
            
            
            
    /** 
             * * * * * * * * * * * * * * * * * 
             *         Vars Initialization
             * * * * * * * * * * * * * * * * *
             */
            
    $this->imgFilePath "phpSortTable/img/";
            
    $this->cssFilePath "phpSortTable/php_sort_table.css";
            
    $this->asc_img "asc.gif";
            
    $this->desc_img "desc.gif";
            
    $this->add_img "add.gif";
            
    $this->delete_img "delete.gif";
            
    $this->edit_img "edit.gif";
            
            
    $this->defaultRowsNum 5;
            
    $this->emptyMsg "No data to be shown.";
        }




         function 
    setPackageFilePath ($path) {
            
    $this->packageFilePath $path;
        }
        
        
            
    /**
         * @access private
         * @return void connect to the database with the configured 
         * connection parameters
         */
         
    function connect(){
            
    $connParam explode(","$this->connectionData4);
            
    $host $connParam[0];
            
    $db $connParam[1];
            
    $user $connParam[2];
            
    $pass $connParam[3];
            
    $connection mysql_connect($host$user$pass) or die(mysql_error());
            
    mysql_select_db($db$connection) or die(mysql_error());
            return 
    $connection;
        }



        
    /**
         * @access public
         * @return void set the format strings for the table
         * @param string $cellpadding cellpading table parameter
         * @param string $cellspacing cellspacing table parameter
         * @param string $border border table parameter
         */
         
    function setTableFormat($cellpadding ""$cellspacing ""$tableborder ""$width ""$tbclass ""$style ""
         {
            
    $this->cellpadding $cellpadding;
            
    $this->cellspacing $cellspacing;
            
    $this->tableborder $tableborder;
            
    $this->width       $width;
            
    $this->tbclass     $tbclass;
            
    $this->style       $style;
        }
        
    /**
         * @access private
         * @return void this is the main function, which should be called by 
         * the application do display the html table
         */
         
    function printTable()
         {

            
    $this->sortby  = isset($_GET['sortby'])?$_GET['sortby']:'';     // column to sort
            
    $this->rows    = isset($_GET['rows'])?$_GET['rows']:'';         // amount of rows to be shown
            
    $this->begin   = isset($_GET['begin'])?$_GET['begin']:'';         // where to begin in the total of rows
            
    $this->sortdir = isset($_GET['sortdir'])?$_GET['sortdir']:'';     // sort direction

            # picks the url vars from the application, if they exist
            
    $this->selfLink $_SERVER['SCRIPT_NAME'] . "?";
            
    $this->urlVars "";
            
            foreach (
    $_GET as $key => $value
            {
                if((
    $key != "sortby") && ($key != "rows") && ($key != "begin") && ($key != "sortdir")) {
                    
    $this->selfLink .= '&' $key '=' $value;
                    
    $this->urlVars .= '&' $key '=' $value;
                }
            }
            if (
    strlen($this->begin) < 1){$this->begin 0;}
            if (
    strlen($this->sortdir) < 1){$this->sortdir "ASC";}
            if (
    strlen($this->rows) < 1){
                
    $this->rows $this->defaultRowsNum;
                
    $this->begin 0;
            }

            
    # executes the db connection
            
    $connection $this->connect();

            
    #  build the SQL Query  
            
    $sql "SELECT * FROM " $this->tableName;
            
            
    #appends the WHERE clause if it exists
            
    if (strlen($this->whereClause) > 0)
                
    $sql .= $this->whereClause;
            
            
    #  appends ORDER BY clause if it is set
            
    if (strlen($this->sortby) > 0)
                
    $sql .= " ORDER BY " $this->sortby " " $this->sortdir;
            
    #  appends LIMIT clause
                
    $sql .= " LIMIT " $this->begin ", " $this->rows;

            
    # builds the query for total rows
                
    $sqlT "SELECT * FROM " $this->tableName;
            
    #appends the WHERE clause if it exists
            
    if (strlen($this->whereClause) > 0)
                
    $sqlT .= $this->whereClause;

            
    # executes the queries
            
    $select mysql_query($sql$connection) or die(mysql_error());
            
    $selectT mysql_query($sqlT$connection) or die(mysql_error());

            
    # changes the sort direction now for the Columns
            
    $this->sortdir = ($this->sortdir == "ASC") ? "ASC" "DESC";
            
    $this->sortimg = ($this->sortdir == "ASC") ? $this->asc_img $this->desc_img;

            
    $this->totalRows mysql_num_rows($selectT);
            
    $this->shownRows mysql_num_rows($select);

            
    $this->colsNum count($this->columns);

            
    /* echo "\n\n\n"; */
            
            # declare the css file if it is defined, else use the default
            
    echo '<link href="'.$this->cssFilePath.'" rel="stylesheet" type="text/css">';

            
    /* $this->printTitle(); */
            
            # if table is empty, shows the Empty Message
            
    if ($this->totalRows 1) {
                
    $this->printEmptyMsg();
            }else{
                
    $this->printHeader();
                
    $this->printContent($select);
            }
            
            
    $this->printFooter();
            
            
    # close the connection
            
    mysql_close($connection);
        }

         function 
    printHeader()
         {
         
          echo 
    '<table cellpadding="'.$this->cellpadding.'" cellspacing="'.$this->cellspacing.'" border="'.$this->tableborder.'" width="'.$this->width .'" class="'.$this->tbclass.'" style="'.$this->style.'">';
              
         
          if(
    count($this->columHeader) > 0)
          {
            echo 
    "<thead>";
              echo 
    "<tr>";
            for(
    $ii=0$ii<count($this->columHeader); $ii++){
       echo 
    '<td id =  "tab'.$this->columHeader[$ii].'"
              class = "'
    .$this->columHeader[$ii]['class'].'" 
              width = "'
    .$this->columHeader[$ii]['width'].'" 
             height = "'
    .$this->columHeader[$ii]['height'].'"
            colspan = "'
    .$this->columHeader[$ii]['colspan'].'" 
              align = "'
    .$this->columHeader[$ii]['align'].'"
             valign = "'
    .$this->columHeader[$ii]['valign'].'" nowrap>
                       '
    .$this->columHeader[$ii]['title'].'</td>';
            }
             echo 
    "</tr>";
            echo 
    "</thead>";
          }
        
        
            
    $index=0;
            echo 
    '<tr id="headerRow">';
            
            
            foreach(
    $this->columns as $column)
            {    
            
                
    $sortLink $this->selfLink '&rows=' .$this->rows.'&begin='.$this->begin;
                
    $sortLink .= ($this->sortdir == 'ASC') ? '&sortdir=DESC' '&sortdir=ASC';
                
    $sortLink .= '&sortby='.$column->name;
                
                
                echo 
    '<td id="headerCell" 
                       class = "'
    .$this->columContent[$index]['class'].'" 
                       width = "'
    .$this->columContent[$index]['width'].'" 
                      height = "'
    .$this->columContent[$index]['height'].'"
                     colspan = "'
    .$this->columContent[$index]['colspan'].'" 
                       align = "'
    .$this->columContent[$index]['align'].'"
                      valign = "'
    .$this->columContent[$index]['valign'].'" nowrap>';
                                           
                echo 
    '[url='$sortLink ']'.$column->title .'[/url]';
                if(
    $this->sortby == $column->name)
                    echo 
    '[img]'.$this->imgFilePath $this->sortimg .'[/img]';
                echo 
    '</td>';
            }

            if (
    strlen($this->editLink) > 0)
                echo 
    "<td></td>";
            if (
    strlen($this->deleteLink) > 0)
                echo 
    "<td></td>";
            echo 
    "</tr>";
            
    $index++;
        }
        
         function 
    printContent($query)
         {
            
    $count 0;    
            while(
    $row mysql_fetch_array($query))
            {
                
                
    # changes the row color with css style
                
    $style = ($count == 0) ? "contentRow1" "contentRow2";
                echo 
    '<tr id="'$style .'" >';

                foreach (
    $this->columns as $key => $column
                {
                
                
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
                # # # # # # # # # # # # # #   PRINT THE COLUMN DATA   # # # # # # # # # # # # #
                # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
                    
                    
    echo '<td id="contentCell">';
                
                        echo  
    htmlspecialchars($row[$column->name]);
                    
                    echo 
    '</td>';
                }


                
    # gets the key and its value for this row
                
    $key $this->urlKeyName;
                
    $keyVal $row[$this->tableKeyName];
                
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
                # # # # # # # #    PRINT THE EDIT AND DELETE BUTTONS DATA     # # # # # # # # #
                # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
                
                # # # # # #   PRINT THE EDIT BUTTON   # # # # # #
                
    if (strlen($this->editLink) > 0){
                
                    
    $eLink $this->editLink "?" $this->urlKeyName "=" $row[$this->tableKeyName] . $this->urlVars;
                
                    echo 
    '<td width="2%" alt="edit" title="edit">';
                    
                    echo 
    '<a';
                        echo 
    ' href='.$eLink.'"';
        
                        if (
    strlen($this->editTarget) > 0){
                            echo 
    ' target="'.$this->editTarget.'"';
                        }
                    echo 
    '>';
                    
                    echo 
    '[img]'.$this->imgFilePath .$this->edit_img '[/img]';
                    
                    echo 
    "</a>";
                    echo 
    "</td>";
                }
                
    # # # # # #   PRINT THE DELETE BUTTON   # # # # # #
                
    if (strlen($this->deleteLink) > 0){
                
                    
    $dLink $this->deleteLink '?' $this->urlKeyName '=' $row[$this->tableKeyName] . $this->urlVars;
                
                    echo 
    '<td width="2%" alt="delete" title="delete">';
                    echo 
    '<a href='.$dLink.'>';
                    echo 
    '[img]'.$this->imgFilePath.$this->delete_img.'[/img]';
                    echo 
    '</a>';
                    echo 
    '</td>';
                }
                echo 
    '</tr>';
                
    $count++;
            }
            echo 
    '<table>';
        }

        
        
        
    /**
         * @access private
         * @return string print the empty message
         */
         
    function printEmptyMsg() {
            echo 
    '<table id="contentTable" "'.$this->formatString.'">';
            echo 
    '<tr id="contentRow1"><td></td></tr>';
            echo 
    '<tr id="contentRow1">';
            echo 
    '<td id="emptyMsg">"'.$this->emptyMsg'"</td>';
            echo 
    '</tr>';
            echo 
    '<tr id="contentRow1"><td></td></tr>';
            echo 
    '</table>';
        }

    }

    class 
    grid {

        var 
    $name;
        function 
    __construct ($name$title) {
            
    $this->name $name;
            
    $this->title $title;

        }
    }
    ?>
    e la richiamo cosi :
    Codice PHP:
        require "../php_sort_table.php";
        
        
    $yourHost     "localhost";
        
    $yourDB     "guru";
        
    $yourUser     "root";
        
    $yourPass    "maurizio";
        
    $yourTable    "tblusers";
        
        
    $dbConnString $yourHost "," $yourDB "," $yourUser "," $yourPass;
        
        
    $sortable = new phpSortTable($dbConnString$yourTable);
        
    # $col = new grid($name,$title,$formatFunction,$link,$img,$appendDataToLink);
        
        
    $col_0 = new grid("UserId""ID");
        
    $col_1 = new grid("Name""Name");
        
    $col_2 = new grid("Email""Email");
        
    $col_3 = new grid("DOB""DOB");
        
    $col_4 = new grid("ru_fp""ru_fp");
        
    $sortable->columns = array(0=>$col_01=>$col_12=>$col_23=>$col_34=>$col_4, );
        
        
    $sortable->setTableFormat ("2""2""0" ,"100%"); // cellpadding, cellspacing, border
        
        
    $sortable->editLink "example_01.php";
        
    $sortable->deleteLink "example_01.php";
        
    $sortable->addLink "addlink.php";
        
    $sortable->addText "add a new entry";
        
    $sortable->urlKeyName "UserId";
        
    $sortable->tableKeyName "UserId";
     
        
    $sortable->columHeader[0]['width'] = "100";
        
    $sortable->columHeader[0]['title'] = "prova";
        
    $sortable->columHeader[1]['width'] = "100";
        
    $sortable->columHeader[1]['title'] = "xxxxxxxxxx";
        
        
        
    $sortable->editTarget "_blank";
        
        
        
        
    #define the deafult row number to be displayed
        
    $sortable->defaultRowsNum "10";
        
        
    #define the path for the css file
        
    $sortable->cssFilePath "../php_sort_table.css";
        
        
    #define the path for of the images directory
        
    $sortable->imgFilePath "../img/";
        
    $sortable->printTable(); 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it L'avatar di echoweb
    Registrato dal
    Sep 2008
    Messaggi
    419
    Questa classe è molto interessante.

    Per quanto riguarda il tuo problema, penso che nel database, il campo email debba contenere una cosa del genere:

    mailto:email@email.it

    e per quanto riguarda il link, una cosa uguale.

  3. #3
    Utente di HTML.it L'avatar di echoweb
    Registrato dal
    Sep 2008
    Messaggi
    419
    Sono curioso di sapere se funziona... funziona??



    "Non soffocare la tua ispirazione e la tua immaginazione,
    non diventare lo schiavo del tuo modello"

    Vincent van Gogh

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ciao funziona tieni la sto cercando di adattare al lavoro che devo fare ti posto la classe corretta e la provi
    Codice PHP:
    error_reporting(E_ALL);

    class 
    phpSortTable
    {
        var 
    $tableName;
        var 
    $urlKeyName;
        var 
    $tableKeyName;
        var 
    $editLink "" ;
        var 
    $editTarget;
        var 
    $editWindowFormat;
        var 
    $deleteLink "" ;
        var 
    $addLink;
        var 
    $addTarget;
        var 
    $addText;
        var 
    $editPromptMsg;
        var 
    $deletePromptMsg;
        var 
    $asc_img;
        var 
    $desc_img;
        var 
    $edit_img;
        var 
    $delete_img;
        var 
    $add_img;
        var 
    $cellpadding "" ;
        var 
    $cellspacing "" ;
        var 
    $tableborder "" ;
        var 
    $width "" ;
        var 
    $tbclass "" ;
        var 
    $style "" ;
        var 
    $columHeader = array();
        var 
    $columContent = array();
        var 
    $tableTitle "" ;
        var 
    $defaultRowsNum;
        var 
    $imgFilePath;
        var 
    $cssFilePath;
        var 
    $emptyMsg;
        var 
    $columns;
        var 
    $selfLink;
        var 
    $urlVars;  
        var 
    $totalRows;
        var 
    $shownRows;
        var 
    $colsNum;
        var 
    $rows;
        var 
    $offset;
        var 
    $sortby;
        var 
    $name "" ;
        var 
    $title "" ;
        
         function 
    __construct($connectionData$tableName) {
            
    $this->connectionData $connectionData;
            
    $this->tableName $tableName;
            
    $this->imgFilePath "phpSortTable/img/";
            
    $this->cssFilePath "phpSortTable/php_sort_table.css";
            
    $this->asc_img "asc.gif";
            
    $this->desc_img "desc.gif";
            
    $this->add_img "add.gif";
            
    $this->delete_img "delete.gif";
            
    $this->edit_img "edit.gif";
            
    $this->defaultRowsNum 5;
            
    $this->emptyMsg "No data to be shown.";
            
    $this->editWindowFormat "";
        }
        
          function 
    phpSortTable($connectionData$tableName) {
            
    $this->connectionData $connectionData;
            
    $this->tableName $tableName;
            
    $this->imgFilePath "phpSortTable/img/";
            
    $this->cssFilePath "phpSortTable/php_sort_table.css";
            
    $this->asc_img "asc.gif";
            
    $this->desc_img "desc.gif";
            
    $this->add_img "add.gif";
            
    $this->delete_img "delete.gif";
            
    $this->edit_img "edit.gif";
            
    $this->defaultRowsNum 5;
            
    $this->emptyMsg "No data to be shown.";
        }

         function 
    setPackageFilePath ($path) {
            
    $this->packageFilePath $path;
        }
        
         function 
    connect(){
            
    $connParam explode(","$this->connectionData4);
            
    $host $connParam[0];
            
    $db $connParam[1];
            
    $user $connParam[2];
            
    $pass $connParam[3];
            
    $connection mysql_connect($host$user$pass) or die(mysql_error());
            
    mysql_select_db($db$connection) or die(mysql_error());
            return 
    $connection;
        }

         function 
    setTableFormat($cellpadding ""$cellspacing ""$tableborder ""$width ""$tbclass ""$style "") {
            
            
    $this->cellpadding $cellpadding;
            
    $this->cellspacing $cellspacing;
            
    $this->tableborder $tableborder;
            
    $this->width       $width;
            
    $this->tbclass     $tbclass;
            
    $this->style       $style;
        }    
        
         function 
    printTable()
         {

            if (!empty(
    $_REQUEST["offset"]) && is_numeric($_REQUEST["offset"]))
            {
                
    $this->offset $_REQUEST["offset"];
            } else {
                
    $this->offset "0";
            }
            
    $this->sortby  = isset($_REQUEST['sortby'])?$_REQUEST['sortby']:'';
            
    $this->sortdir = isset($_REQUEST['sortdir'])?$_REQUEST['sortdir']:'';        $this->rows    = isset($_REQUEST['rows'])?$_REQUEST['rows']:'';             if (substr($_SERVER['SCRIPT_NAME'] , -4) == '.php'){
            
    $this->selfLink $_SERVER['SCRIPT_NAME'] . '?';
            }else{
            
    $this->selfLink $_SERVER['SCRIPT_NAME'] . '&';
            }    
            if (
    substr($this->urlVars , -4) == '.php'){
            
    $this->urlVars "" '?';
            }else{
            
    $this->urlVars "" '&';
            }
            foreach (
    $_GET as $key => $value) {
            if((
    $key != "sortby") && ($key != "rows") && ($key != "offset") && ($key != "sortdir")) {
                
                    
    $this->selfLink .=  $key '=' $value;
                    
    $this->urlVars  .=  $key '=' $value;
                }
            }
            if (
    strlen($this->sortdir) < 1){$this->sortdir "ASC";}
            if (
    strlen($this->rows) < 1){
                
    $this->rows $this->defaultRowsNum;

            }
            
    $connection $this->connect();
            
    $sql "SELECT * FROM " $this->tableName;
            
    /*         #appends the WHERE clause if it exists
     *        if (strlen($this->whereClause) > 0)
     *            $sql .= $this->whereClause;
     */        
            
    if (strlen($this->sortby) > 0)
                
    $sql .= " ORDER BY " $this->sortby " " $this->sortdir;
                
    $sql .= " LIMIT " $this->offset ", " $this->rows;
       
    /*  $sqlT = "SELECT * FROM " . $this->tableName;
        *     #appends the WHERE clause if it exists
        *    if (strlen($this->whereClause) > 0)
        *        $sqlT .= $this->whereClause;
        */
            
    $select mysql_query($sql$connection) or die(mysql_error());
            
    $this->sortdir = ($this->sortdir == "ASC") ? "ASC" "DESC";
            
    $this->sortimg = ($this->sortdir == "ASC") ? $this->asc_img $this->desc_img;
            
    $this->totalRows mysql_num_rows($select);
            
    $this->shownRows mysql_num_rows($select);
            
    $this->colsNum count($this->columns);
            echo 
    '<link href="'.$this->cssFilePath.'" rel="stylesheet" type="text/css">';    
            
    # if table is empty, shows the Empty Message
            
    if ($this->totalRows 1) {
                
    $this->printEmptyMsg();
            }else{
                
    $this->printHeader();
                
    $this->printContent($select);
            }
            
    $this->printFooter();
            
    mysql_close($connection);
        }
         function 
    printHeader()
         {    
          echo 
    '<table cellpadding="'.$this->cellpadding.'" cellspacing="'.$this->cellspacing.'" border="'.$this->tableborder.'" width="'.$this->width .'" class="'.$this->tbclass.'" style="'.$this->style.'">';
          if(
    count($this->columHeader) > 0) {
            echo 
    "<thead>";
              echo 
    "<tr>";
                for(
    $ii=0$ii<count($this->columHeader); $ii++){
                 echo 
    '<td id =  "tab'.$this->columHeader[$ii].'"';
                    if(!empty(
    $this->columHeader[$ii]['class']))    echo 'class   = "'.$this->columHeader[$ii]['class'].'"'
                    if(!empty(
    $this->columHeader[$ii]['width']))    echo 'width   = "'.$this->columHeader[$ii]['width'].'"';
                    if(!empty(
    $this->columHeader[$ii]['height']))   echo 'height  = "'.$this->columHeader[$ii]['height'].'"'
                    if(!empty(
    $this->columHeader[$ii]['colspan']))  echo 'colspan = "'.$this->columHeader[$ii]['colspan'].'"';
                    if(!empty(
    $this->columHeader[$ii]['align']))    echo 'align   = "'.$this->columHeader[$ii]['align'].'"';  
                    if(!empty(
    $this->columHeader[$ii]['valign']))   echo 'valign  = "'.$this->columHeader[$ii]['valign'].'"';  
                 echo 
    'nowrap="nowrap">';
             echo 
    $this->columHeader[$ii]['title'] ;
            echo  
    '</td>';
            }
            echo 
    "</tr>";
          echo 
    "</thead>";
          }
            if(
    substr($_SERVER['SCRIPT_NAME'] , -4) == '.php'){
            
    $this->selfLink $_SERVER['SCRIPT_NAME'] . '?';
            }else{
            
    $this->selfLink $_SERVER['SCRIPT_NAME'] . '&';
            }
            
    $index=0;
            echo 
    '<tr id="headerRow">';
            foreach(
    $this->columns as $column){    
                
    $sortLink $this->selfLink 'rows=' .$this->rows.'&offset='.$this->offset;
                
    $sortLink .= '&sortby='.$column->name;
                
    $sortLink .= ($this->sortdir == 'ASC') ? '&sortdir=DESC' '&sortdir=ASC';    
                echo 
    '<td id="headerCell"'
                    if(!empty(
    $this->columContent[$index]['class']))    echo 'class   = "'.$this->columContent[$index]['class'].'"';   
                    if(!empty(
    $this->columContent[$index]['width']))    echo 'width   = "'.$this->columContent[$index]['width'].'"';  
                    if(!empty(
    $this->columContent[$index]['height']))   echo 'height  = "'.$this->columContent[$index]['height'].'"';  
                    if(!empty(
    $this->columContent[$index]['colspan']))  echo 'colspan = "'.$this->columContent[$index]['colspan'].'"'
                    if(!empty(
    $this->columContent[$index]['align']))    echo 'align   = "'.$this->columContent[$index]['align'].'"';  
                    if(!empty(
    $this->columContent[$index]['valign']))   echo 'valign  = "'.$this->columContent[$index]['valign'].'"';  
                 echo 
    'nowrap="nowrap">';                
                    echo 
    '[url='$sortLink ']'.$column->title .'[/url]';
                if(
    $this->sortby == $column->name)
            echo 
    '[img]'.$this->imgFilePath $this->sortimg .'[/img]';
                    echo 
    '</td>';
            }
            if (
    strlen($this->editLink) > 0)
                echo 
    "<td></td>";
            if (
    strlen($this->deleteLink) > 0)
                echo 
    "<td></td>";
            echo 
    "</tr>";
            
    $index++;
        }
        
         function 
    printContent($query){
            
    $count 0;    
            while(
    $row mysql_fetch_array($query)){
                
    $style = ($count == 0) ? "contentRow1" "contentRow2";
                echo 
    '<tr id="'$style .'" >';
                foreach (
    $this->columns as $key => $column) {
                    echo 
    '<td id="contentCell">';
                        echo  
    htmlspecialchars($row[$column->name]);
                    echo 
    '</td>';
                }
                
    $key $this->urlKeyName;
                
    $keyVal $row[$this->tableKeyName];
                if (
    strlen($this->editLink) > 0){
                    if (
    substr($this->editLink , -4) == '.php'){
                       
    $eLink $this->editLink "?" $this->urlKeyName "=" $row[$this->tableKeyName] . $this->urlVars;
                    } else {
                       
    $eLink $this->editLink "&" $this->urlKeyName "=" $row[$this->tableKeyName] . $this->urlVars;
                    }
                    echo 
    '<td width="2%" alt="edit" title="edit">';
                    echo 
    '<a href='.$eLink.'>';
                    
                    echo 
    '[img]'.$this->imgFilePath .$this->edit_img '[/img]';
                    echo 
    "</a>";
                    echo 
    "</td>";
                }
                if (
    strlen($this->deleteLink) > 0){
                    if (
    substr($this->deleteLink , -4) == '.php'){
                       
    $dLink $this->deleteLink '?' $this->urlKeyName '=' $row[$this->tableKeyName] . $this->urlVars;
                    } else {
                       
    $dLink $this->deleteLink '&' $this->urlKeyName '=' $row[$this->tableKeyName] . $this->urlVars;
                    }
                    echo 
    '<td width="2%" alt="delete" title="delete">';
                    echo 
    '<a href='.$dLink.' >';
                    echo 
    '[img]'.$this->imgFilePath.$this->delete_img.'[/img]';
                    echo 
    '</a>';
                    echo 
    '</td>';
                }
                echo 
    '</tr>';
                
    $count++;
            }
            echo 
    '<table>';
        }
         function 
    printFooter() {

         }
         function 
    printEmptyMsg() {
            echo 
    '<table id="contentTable" "'.$this->formatString.'">';
            echo 
    '<tr id="contentRow1"><td></td></tr>';
            echo 
    '<tr id="contentRow1">';
            echo 
    '<td id="emptyMsg">"'.$this->emptyMsg'"</td>';
            echo 
    '</tr>';
            echo 
    '<tr id="contentRow1"><td></td></tr>';
            echo 
    '</table>';
        }

    }
    class 
    displayGrid {

        var 
    $name;
        var 
    $title;
        function 
    __construct ($name$title) {
            
    $this->name $name;
            
    $this->title $title;
        }

    la inserisci nei tuoi lavori cosi
    Codice PHP:
        require "../php_sort_table.php";
        
    $yourHost     "localhost";
        
    $yourDB     "guru";
        
    $yourUser     "root";
        
    $yourPass    "maurizio";
        
    $yourTable    "tblusers";
        
    $dbConnString $yourHost "," $yourDB "," $yourUser "," $yourPass;
        
    $sortable = new phpSortTable($dbConnString$yourTable);    
        
    $col_0 = new displayGrid("UserId""ID");
                 
    $col_1 = new displayGrid("Name""Name");
        
    $col_2 = new displayGrid("Email""Email");
                 
    $col_3 = new displayGrid("DOB""DOB");
                 
    $col_4 = new displayGrid("ru_fp""ru_fp");
         
    $sortable->columns = array(0=>$col_01=>$col_12=>$col_23=>$col_34=>$col_4, ); 
        
        
    $sortable->setTableFormat ("2""2""0" ,"100%"); 
        
    $sortable->editLink "example_01.php?delete=user";
        
    $sortable->deleteLink "example_01.php";
        
    $sortable->addLink "addlink.php";
        
    $sortable->addText "add a new entry";
        
    $sortable->urlKeyName "UserId";
        
    $sortable->tableKeyName "UserId";
        
    $sortable->columHeader[0]['width'] = "100";
        
    $sortable->columHeader[0]['title'] = "prova";
        
    $sortable->columHeader[1]['width'] = "100";
        
    $sortable->columHeader[1]['title'] = "xxxxxxxxxx";
        
    /* $sortable->editTarget = "_blank"; */
        #define the deafult row number to be displayed
        
    $sortable->defaultRowsNum "10";
        
    #define the path for the css file
        
    $sortable->cssFilePath "../php_sort_table.css";    
        
    #define the path for of the images directory
        
    $sortable->imgFilePath "../img/";
        
    $sortable->printTable(); 
    ti posto il database
    codice:
    CREATE TABLE `tblusers` (
      `UserId` int(11) NOT NULL auto_increment,
      `Name` varchar(50) NOT NULL default '',
      `Email` varchar(255) NOT NULL default '',
      `DOB` text NOT NULL,
      `ru_fp` bigint(11) NOT NULL,
      PRIMARY KEY  (`UserId`)
    ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;
    INSERT INTO `tblusers` VALUES (9, 'Neeraj', 'neeraj@yahool.com', '1980-04-04', 0);
    INSERT INTO `tblusers` VALUES (10, 'tqtet', 'tqewtewqt', '1980-04-04', 0);
    INSERT INTO `tblusers` VALUES (11, 'uffa', 'fsafasf', '1979-05-01', 0);
    INSERT INTO `tblusers` VALUES (13, 'cazzo', 'figa', '1980-04-04', 0);
    INSERT INTO `tblusers` VALUES (14, 'yyyffff', 'fffffff@bfbf.com', '1979-01-01', 0);
    INSERT INTO `tblusers` VALUES (15, '1980-04-04', '1980-04-04', '1980-04-04', 0);
    INSERT INTO `tblusers` VALUES (19, 'ewqet', 'weqtewqt', '0', 1);
    INSERT INTO `tblusers` VALUES (20, 'weqtewqt', 'ewqt', '1', 1);
    INSERT INTO `tblusers` VALUES (21, 'wqtet', 'etew', 'twqt', 1);
    INSERT INTO `tblusers` VALUES (22, 'wqtewt', 'ewtewtwe', 'ttwqtqewt', 1);
    INSERT INTO `tblusers` VALUES (23, 'wqetewtee', 'wetet', '1', 1);
    INSERT INTO `tblusers` VALUES (24, '12341325', '3215325', '1', 1);
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    Utente di HTML.it L'avatar di echoweb
    Registrato dal
    Sep 2008
    Messaggi
    419
    Molto gentile. Grazie.


    "Non soffocare la tua ispirazione e la tua immaginazione,
    non diventare lo schiavo del tuo modello"

    Vincent van Gogh

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.