Ver Mensaje Individual
  #6 (permalink)  
Antiguo 01/08/2011, 06:45
tumbero_x
 
Fecha de Ingreso: octubre-2010
Ubicación: Buenos Aires
Mensajes: 557
Antigüedad: 13 años, 6 meses
Puntos: 4
Respuesta: Unir dos columnas

el problema que tengo realmente es mi poco conocimiento ya que estoy trabajando con datatables y con un archivo server_processing.php , entonces estoy tratando de modificar este archivo para que me muestre 2 campos mysql unidos (es solamente para que tenga una mejor presentacion a la hora de que el usuario los vea)
te dejo el archivo por si me podes dar una mano
Te agradezco un monton!!!
Código PHP:
Ver original
  1. <?php
  2.     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3.      * Easy set variables
  4.      */
  5.    
  6.     /* Array of database columns which should be read and sent back to DataTables. Use a space where
  7.      * you want to insert a non-database field (for example a counter or static image)
  8.      
  9.      */
  10.      require_once('class/class.php');
  11.      
  12.      
  13.     $aColumns = array('compra_id','razon_social','compra_fc','compra_num_suc','compra_num_com','moneda_id','compra_coti','compra_total','compra_usuario','compra_fecha');
  14.    
  15.     /* Indexed column (used for fast and accurate table cardinality) */
  16.     $sIndexColumn = "compra_id";
  17.    
  18.     /* DB table to use */
  19.     $sTable = "compras";
  20.    
  21.    
  22.      
  23.     $sLimit = "";
  24.     if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
  25.     {
  26.         $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
  27.             mysql_real_escape_string( $_GET['iDisplayLength'] );
  28.     }
  29.    
  30.    
  31.     /*
  32.      * Ordering
  33.      */
  34.     $sOrder = "";
  35.     if ( isset( $_GET['iSortCol_0'] ) )
  36.     {
  37.         $sOrder = "ORDER BY  ";
  38.         for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
  39.         {
  40.             if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
  41.             {
  42.                 $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
  43.                     ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
  44.             }
  45.         }
  46.        
  47.         $sOrder = substr_replace( $sOrder, "", -2 );
  48.         if ( $sOrder == "ORDER BY" )
  49.         {
  50.             $sOrder = "";
  51.         }
  52.     }
  53.    
  54.    
  55.     /*
  56.      * Filtering
  57.      * NOTE this does not match the built-in DataTables filtering which does it
  58.      * word by word on any field. It's possible to do here, but concerned about efficiency
  59.      * on very large tables, and MySQL's regex functionality is very limited
  60.      */
  61.     $sWhere = "";
  62.     if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
  63.     {
  64.         $sWhere = "WHERE (";
  65.         for ( $i=0 ; $i<count($aColumns) ; $i++ )
  66.         {
  67.             $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
  68.         }
  69.         $sWhere = substr_replace( $sWhere, "", -3 );
  70.         $sWhere .= ')';
  71.     }
  72.    
  73.     /* Individual column filtering */
  74.     for ( $i=0 ; $i<count($aColumns) ; $i++ )
  75.     {
  76.         if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
  77.         {
  78.             if ( $sWhere == "" )
  79.             {
  80.                 $sWhere = "WHERE ";
  81.             }
  82.             else
  83.             {
  84.                 $sWhere .= " AND ";
  85.             }
  86.             $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
  87.         }
  88.     }
  89.    
  90.    
  91.     /*
  92.      * SQL queries
  93.      * Get data to display
  94.      */
  95.     $sQuery = "
  96.         SELECT  SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
  97.         FROM   $sTable  LEFT OUTER JOIN  proveedores ON $sTable.compra_cod_prov=proveedores.proveedor_id LEFT OUTER JOIN monedas ON $sTable.compra_moneda=monedas.mone_id
  98.         $sWhere
  99.         $sOrder
  100.         $sLimit
  101.     ";
  102.     $rResult = mysql_query( $sQuery,Conectar::con() ) or die(mysql_error());
  103.    
  104.     /* Data set length after filtering */
  105.     $sQuery = "
  106.         SELECT FOUND_ROWS()
  107.     ";
  108.     $rResultFilterTotal = mysql_query( $sQuery, Conectar::con() ) or die(mysql_error());
  109.     $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
  110.     $iFilteredTotal = $aResultFilterTotal[0];
  111.    
  112.     /* Total data set length */
  113.     $sQuery = "
  114.         SELECT COUNT(".$sIndexColumn.")
  115.         FROM   $sTable
  116.     ";
  117.     $rResultTotal = mysql_query( $sQuery, Conectar::con() ) or die(mysql_error());
  118.     $aResultTotal = mysql_fetch_array($rResultTotal);
  119.     $iTotal = $aResultTotal[0];
  120.    
  121.    
  122.     /*
  123.      * Output
  124.      */
  125.     $output = array(
  126.         "sEcho" => intval($_GET['sEcho']),
  127.         "iTotalRecords" => $iTotal,
  128.         "iTotalDisplayRecords" => $iFilteredTotal,
  129.         "aaData" => array(
  130.        
  131.     )
  132.     );
  133.    
  134.    
  135.     while ( $aRow = mysql_fetch_array( $rResult ) )
  136.     {
  137.         $row = array();
  138.         for ( $i=0 ; $i<count($aColumns) ; $i++ )
  139.         {
  140.             if ( $aColumns[$i] == "version" )
  141.             {
  142.                 /* Special output formatting for 'version' column */
  143.                 $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
  144.             }
  145.             else if ( $aColumns[$i] != ' ' )
  146.             {
  147.                 /* General output */
  148.                 $row[] = $aRow[ $aColumns[$i] ];
  149.             }
  150.         }
  151.        
  152.         $output['aaData'][] = $row;
  153.        
  154.        
  155.     }
  156.    
  157.    
  158.    
  159.     echo json_encode($output);
  160.    
  161.    
  162. ?>

ejemplo: necesito que compra_num_suc y compra_num_com se muestren en una misma columna separados por un espacio o por un guion