1. #1
    Ext User
    Join Date
    Feb 2008
    Posts
    275
    Vote Rating
    0
    Rafael is on a distinguished road

      0  

    Default How to use Select with inner join in Short Colunm Grid

    How to use Select with inner join in Short Colunm Grid


    Code:
     
    $query = "SELECT * FROM Chamado CH, Funcionario FU, Empresa EM where CH.codigo_funcionario = FU.codigo_funcionario and CH.codigo_empresa = EM.codigo_empresa ";
    I have this query, and i need to use
    Code:
    $_POST[short]
    in oder by but in my query have alias in the tables.
    How to use this ?

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    77
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    How is this related to Ext?

  3. #3
    Ext User
    Join Date
    Feb 2008
    Posts
    275
    Vote Rating
    0
    Rafael is on a distinguished road

      0  

    Default


    select.php
    Code:
     
    if( $parametro == "Chamado" ){
     if( isset($_POST[sort]) && isset($_POST[dir]) ){
      $order = explode("_", $_POST[sort]);
      $order = strtoupper( substr($order[1], 0, 2)) .".". $_POST[sort];
      $direc = $_POST[dir];
      $query = "SELECT * FROM Chamado CH, Funcionario FU, Empresa EM where CH.codigo_funcionario = FU.codigo_funcionario and CH.codigo_empresa = EM.codigo_empresa ORDER BY $order $direc ";
     }
     else { 
      $query = "SELECT * FROM Chamado CH, Funcionario FU, Empresa EM where CH.codigo_funcionario = FU.codigo_funcionario and CH.codigo_empresa = EM.codigo_empresa "; 
     }
     $result = mysql_query($query);
     $total = mysql_num_rows($result);
     $inicio = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
     $limite = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
     $limit = $query." LIMIT ".$inicio.",".$limite;  
     $rs = mysql_query($limit);  
     $arr = array();
     while($obj = mysql_fetch_object($rs))
     {
      $arr[] = $obj;
     }
     echo $_GET['callback'].'({"total":"'.$total.'","resultado":'.json_encode($arr).'})'; 
    }
    Code:
     
        var dsChamado = new Ext.data.Store({
        baseParams: { parametro: 'Chamado' },
        remoteSort: true,
              proxy: new Ext.data.HttpProxy({
                   url: 'select.php',
                   method: 'post'
              }),
              reader: new Ext.data.JsonReader({
                   root:'resultado',
                   totalProperty: 'total',
                   id:'codigo_chamado'
              },[
                {name: 'codigo_chamado', mapping: 'codigo_chamado', hidden: true, type: 'int'},
                {name: 'codigo_empresa', mapping: 'codigo_empresa', type: 'int'},
                {name: 'nome_empresa', mapping:'nome_empresa', type:'string'},
                {name: 'nome_funcionario', mapping:'nome_funcionario', type:'string'},
                {name: 'data_abertura', mapping:'data_abertura', type: 'date', dateFormat: 'Y-m-d'},
               {name: 'data_encerramento', mapping:'data_encerramento', type: 'date', dateFormat: 'Y-m-d'},
               {name: 'status', mapping: 'status', type: 'bool'},
               {name: 'Fechar', mapping: 'status', type: 'bool'},
              ])
         });
    is here my column of the grid
    Code:
          columns: [{
          id:'codigo_empresa',
          header: "codigo_empresa",
          dataIndex: 'codigo_empresa',
          width: 220,
          hidden: true,
          sortable: true,
          type: 'int',
          align: 'center',
         },{
          header: "Nome Empresa",
          dataIndex: 'nome_empresa',
          width: 170,
          sortable: true,
          type: 'string',
          align: 'center',
         },{
          header: "Nome Funcionario",
          dataIndex: 'nome_funcionario',
          width: 220,
          sortable: true,
          type: 'string',
          align: 'center',
         },{
          header: "Aberto em",
          dataIndex: 'data_abertura',
          renderer: formatDate,
          width: 100,
          sortable: true,
          type: 'date',
          align: 'center',
         },{
          header: "Finalizado em",
          dataIndex: 'data_encerramento',
          renderer: formatDate,
          width: 100,
          sortable: true,
          type: 'date',
          align: 'center',
         },{
          //checkColumn
          header: "Status",
                dataIndex: 'status',
          renderer: Status,
                width: 100,
          sortable: true,
          type: 'bool',
                align: 'center',      
         },{
                header: "Encerrar",
          dataIndex: 'status',
          renderer: fechar,
                width: 67,
                align: 'center',
         }],

  4. #4
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    77
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    OK, what exactly is the problem?

  5. #5
    Ext User
    Join Date
    Feb 2008
    Posts
    275
    Vote Rating
    0
    Rafael is on a distinguished road

      0  

    Default


    My probleman is a query. I use inner join and i dont know to use $_POST[sort] with alias.

    Example:

    Code:
     
    $query = "SELECT * FROM Chamado CH, Funcionario FU, Empresa EM where CH.codigo_funcionario = FU.codigo_funcionario and CH.codigo_empresa = EM.codigo_empresa order by $_POST[sort] $_POST[dir] ";
    $_POST[sort] come to grid but in grid have column of the tree table of database. My probleman is use to alias.$_POST[sort]

Thread Participants: 1