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

    classe per datagrid inserimento di una query dentro un array

    salve ragazzi dovrei inserire dentro un array il contenuto di una query tipo
    Codice PHP:

                    
    echo '[url='$sortLink ']'.$column->title .'[/url]';
                if(
    $this->sortby == $column->name)
                    echo 
    '[img]'.$this->imgFilePath $this->sortimg .'[/img]'
    cosi :
    Codice PHP:

                
    echo '[url='$sortLink ']'.$this->columContent[$index][$column->title] .'[/url]';
                if(
    $this->sortby == $column->name)
                    echo 
    '[img]'.$this->imgFilePath $this->sortimg .'[/img]'
    questa e la classe
    Codice PHP:
    error_reporting(E_ALL);

    class 
    Grid
    {
        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;

         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 
    Grid($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 
    start($name$title$selectquery$countquery$searchquery$fields$options){
         }
         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']:'';     // column to sort
            
    $this->sortdir = isset($_REQUEST['sortdir'])?$_REQUEST['sortdir']:'';     // sort direction
            
    $this->rows    = isset($_REQUEST['rows'])?$_REQUEST['rows']:'';         // amount of rows to be shown
            
            
            
            
    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;
     */
            # 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($select);
            
    $this->shownRows mysql_num_rows($select);
            
    $this->colsNum count($this->columns);

            
            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();
            
            
            
    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'].'';   else echo $this->columHeader[$ii]['class'] = '';
                    if(!empty(
    $this->columHeader[$ii]['width']))    echo 'width   = '.$this->columHeader[$ii]['width'].'';   else echo $this->columHeader[$ii]['width'] = '';
                    if(!empty(
    $this->columHeader[$ii]['height']))   echo 'height  = '.$this->columHeader[$ii]['height'].'';  else echo $this->columHeader[$ii]['height'] = '';
                    if(!empty(
    $this->columHeader[$ii]['colspan']))  echo 'colspan = '.$this->columHeader[$ii]['colspan'].''; else echo $this->columHeader[$ii]['colspan'] = '';
                    if(!empty(
    $this->columHeader[$ii]['align']))    echo 'align   = '.$this->columHeader[$ii]['align'].'';   else echo $this->columHeader[$ii]['align'] = '';
                    if(!empty(
    $this->columHeader[$ii]['valign']))   echo 'valign  = '.$this->columHeader[$ii]['valign'].'';  else echo $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'].'';   else echo $this->columContent[$index]['class'] = '';
                    if(!empty(
    $this->columContent[$index]['width']))    echo 'width   = '.$this->columContent[$index]['width'].'';   else echo $this->columContent[$index]['width'] = '';
                    if(!empty(
    $this->columContent[$index]['height']))   echo 'height  = '.$this->columContent[$index]['height'].'';  else echo $this->columContent[$index]['height'] = '';
                    if(!empty(
    $this->columContent[$index]['colspan']))  echo 'colspan = '.$this->columContent[$index]['colspan'].''; else echo $this->columContent[$index]['colspan'] = '';
                    if(!empty(
    $this->columContent[$index]['align']))    echo 'align   = '.$this->columContent[$index]['align'].'';   else echo $this->columContent[$index]['align'] = '';
                    if(!empty(
    $this->columContent[$index]['valign']))   echo 'valign  = '.$this->columContent[$index]['valign'].'';  else echo $this->columContent[$index]['valign'] = '';
                 echo 
    'nowrap="nowrap">';
                                   
                    echo 
    '[url='$sortLink ']'.$this->columContent[$index][$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;
        }

    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    1,317
    non ho capito la domanda, quale dei due codici devi inserire? e soprattutto dove?

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    ciao dovrei inserire il primo nel secondo come postato
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    scusate mi da un errore perche ? l errore e :
    codice:
    Notice: Trying to get property of non-object in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\phpsorttable\php_sort_table.php on line
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    salve a tutti , ho cambiato modo di passare i dati all datagrid , mentre prima li passavo con un altra classe , adesso li passo con la stessa classe cosi
    Codice PHP:

        $sortable
    ->displayGrid("UserId""ID");
        
    $sortable->displayGrid("Name""Name");
        
    $sortable->displayGrid("Email""Email");
        
    $sortable->displayGrid("DOB""DOB");
        
    $sortable->displayGrid("ru_fp""ru_fp"); 
    e riceve i dati cosi :
    Codice PHP:

        
    function displayGrid($name$title) {
        
            
    $this->name[] = $name;
            
    $this->title[] = $title;
            
    $this->columContent = array($this->name $this->title);
        } 
    però , mi stampa un errore

    codice:
    Warning: Invalid argument supplied for foreach() in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\phpsorttable\php_sort_table.
    questo e il foreach dell errore :
    Codice PHP:


            
    foreach($this->columContent 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>';
            } 
    perche ? cosa sto sbagliando ? grazie
    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.