good day The problem that I have is that in my datatable I want it to show certain data with a style TO A COLUMN IN SPECIFIC, for example with $ for prices, or the dates with its format, etc. only that when doing this code, it only replaces what is equal to the value of the column
if($aRow[ $aColumnas[$i] ]==$aRow['totalCompra']){
$row[]= "<td>$ ".number_format($aRow['totalCompra'])."</td>";
}else
$row[] = $aRow[ $aColumnas[$i]];
all the data that is equal puts them in that format. For example, in this image, $ is repeated in two 1
here is the complete code
<?php
/*
* Script: Tablas de multiples datos del lado del servidor para PHP y MySQL
* Copyright: 2016 - Marko Robles
* License: GPL v2 or BSD (3-point)
*/
///////////PRODUCTOS //////////////////
require_once( "class.php" );
$obj = new Trabajo(); //conexion
$idCarrito = 2; //ES
$agregar=0;
require '../php_conexion.php';
/* Nombre de La Tabla */
$sTabla = "compras";
/* Array que contiene los nombres de las columnas de la tabla*/
$aColumnas = array( 'idCompra','numeroCompra','idDistr','fechaCompra','formaPago', 'articulos' ,'totalCompra','statusCompra');
/* columna indexada */
$sIndexColumn = "idCompra";
// Paginacion
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".$_GET['iDisplayStart'].", ".$_GET['iDisplayLength'];
}
//Ordenacion
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$sOrder .= $aColumnas[ intval( $_GET['iSortCol_'.$i] ) ]."
".$_GET['sSortDir_'.$i] .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
//Filtracion
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumnas) ; $i++ )
{
$sWhere .= $aColumnas[$i]." LIKE '%".$_GET['sSearch']."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
// Filtrado de columna individual
for ( $i=0 ; $i<count($aColumnas) ; $i++ )
{
if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumnas[$i]." LIKE '%".$_GET['sSearch_'.$i]."%' ";
}
}
//Obtener datos para mostrar SQL queries
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumnas))."
FROM $sTabla
$sWhere
$sOrder
$sLimit
";
$rResult = $conexion->query($sQuery);
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = $conexion->query($sQuery);
$aResultFilterTotal = $rResultFilterTotal->fetch_array();
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTabla
";
$rResultTotal = $conexion->query($sQuery);
$aResultTotal = $rResultTotal->fetch_array();
$iTotal = $aResultTotal[0];
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = $rResult->fetch_array())
{
$row = array();
for ( $i=0 ; $i<count($aColumnas) ; $i++ )
{
if ( $aColumnas[$i] == "version" )
{
/* Special output formatting for 'version' column */
$row[] = ($aRow[ $aColumnas[$i] ]=="0") ? '-' : $aRow[ $aColumnas[$i] ];
}
else if ( $aColumnas[$i] != ' ' )
{
/* General output */
if($aRow[ $aColumnas[$i] ]==$aRow['totalCompra']){
$row[]= "<td>$ ".number_format($aRow['totalCompra'])."</td>";
}else
$row[] = $aRow[ $aColumnas[$i]];
// }
}
}
$row[]="<a href='compraDetalles.php?idc=".$aRow['numeroCompra']."'><button name='compraDetalles' type='submit' class='btn btn-large btn-primary' value='Detalles' >DETALLES<span class='glyphicon glyphicon-shopping-cart'></span></button></a>";
$row[]="<a href='detalles_FACTURA.php?idc=".$aRow['numeroCompra']."'><button name='factura' type='submit' class='btn btn-large btn-primary' value='factura' >FACTURA<span class='glyphicon glyphicon-shopping-cart'></span></button></a>";
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>