What happens is that I grab a page already on the internet, and I want it to make a search in the box, a specific search within what is already filtered.
//Filtracion
$sWhere = "WHERE nomTipo ='Administrador'";//filtra los que solo son administradores
that is the line where the filtering of pure administrators,
What happens is that when I do the search with the box it removes the filtering that I already had and looks for everything in the table, I want to put that restriction,
you are 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)
*/
require '../php_conexion.php';
/* Nombre de La Tabla */
$sTabla = "usuarios";
/* Array que contiene los nombres de las columnas de la tabla*/
$aColumnas = array( 'nomTipo','idUsuario','nomUsuario', 'nickUsuario', 'ultFechaActivo','emailUsuario','telUsuario','nomDistrOrigen','estadoDistr','estado');
/* columna indexada */
$sIndexColumn = "nomTipo";
// 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 = "WHERE nomTipo ='Administrador'";//filtra los que solo son administradores
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())
{
// if( $aRow['nomTipo']=='Distribuidor'){
$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['ultFechaActivo']){
$row[]=strftime( "%d de %B de %Y",strtotime( $aRow['ultFechaActivo']));
}else if($aRow[$aColumnas[$i]]==$aRow['idUsuario']){
}else {
$row[] = $aRow[ $aColumnas[$i]];
}
}
}
$row[] = "<td><a href='detalles_usuario.php?ID=".$aRow['idUsuario']."'><span class='glyphicon glyphicon-pencil'></span></a></td>";
#$row[]= "<td><img src=".$aRow['imag1']." width=70 heigth=70 ></td>";
$output['aaData'][] = $row;
//}
}
echo json_encode( $output );
?>
This is my table already filtered, as in the code
there is already filtered that I have in the code, by TYPE-ADMINISTRATOR but if in the search box I put anything, "a" for example, it looks for all the things that have "a" of all my table and removes the filtered that I already had ADMINISTRATORS ASI
I think something has to be in the part where I say FILTRACION of my code, but I do not know where and how to make that change so that it looks only in what I have already filtered