Filtering data by server side php variable for particular values from a column in datatable
Filtering data by server side php variable for particular values from a column in datatable
I'm using Datatables examples files (server side) html and php for my porpouse.
the structure I have is:
../firstfile.html
../scripts/server_processing.php
I insterted a script into de server_processing.php file, where I obtained the variable $username from another part of my CMS.
I want´t to manage to filter my datatable shown in .../fistfile.html filtered by the username logged when I call the fistfile.html, and $userame from server_processing.php should match and be used to filter one of the columns from my datatable.
example:
in server_processing.php I get the username logged into the actual session: $username = 'Daniel';
In firstfile.html I shold see only data filter by 'Daniel' in the second column:
Original datatable:
_____________________________
| ID | username | Value |
_____________________________
| 1 | Juan | 5 |
| 2 | Daniel | 3 |
| 3 | Pedro | 5 |
_____________________________
filter result from logged user, variable $username = 'Daniel' stored in server_processing.php:
_____________________________
| ID | username | Value |
_____________________________
| 2 | Daniel | 3 |
_____________________________
how can I manage to do this... sory for my bad explanation, hope you understand... I'm not english native and I have been reading to find how to solve this, but haven't find any solution yet... thanks for any help you could give me!
regards,
Daniel
firstfile.html code:
[code]
Oper
Lote
Juliano
Fecha
Lote/Juliano Origen
Enviado
Rechazado
Validado
Recibido
Rechazo Op
Estado
Comentarios
Cargando datos del servidor
Oper
Lote
Juliano
Fecha
Lote/Juliano Origen
Enviado
Rechazado
Validado
Recibido
Rechazo Op
Estado
Comentarios
[/code]
scripts/server_processing.php code:
...
[code]
$ruta_a_joomla = "/../";
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__)."/../".$ruta_a_joomla ));
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE2', realpath(dirname(__FILE__)."/../../" ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE2 .DS.'configuration.php' );
$mainframe =& JFactory::getApplication('site'); //llama a joomla puedes poner 'admin' si quieres que valide en el back
$mainframe->initialise(); //inicio a la aplicación
$userjoomla = &JFactory::getUser(); //llamas la clase
$username = $userjoomla->username;
[/code]
...the resto of the code is the same from datatables serverside example code...
the structure I have is:
../firstfile.html
../scripts/server_processing.php
I insterted a script into de server_processing.php file, where I obtained the variable $username from another part of my CMS.
I want´t to manage to filter my datatable shown in .../fistfile.html filtered by the username logged when I call the fistfile.html, and $userame from server_processing.php should match and be used to filter one of the columns from my datatable.
example:
in server_processing.php I get the username logged into the actual session: $username = 'Daniel';
In firstfile.html I shold see only data filter by 'Daniel' in the second column:
Original datatable:
_____________________________
| ID | username | Value |
_____________________________
| 1 | Juan | 5 |
| 2 | Daniel | 3 |
| 3 | Pedro | 5 |
_____________________________
filter result from logged user, variable $username = 'Daniel' stored in server_processing.php:
_____________________________
| ID | username | Value |
_____________________________
| 2 | Daniel | 3 |
_____________________________
how can I manage to do this... sory for my bad explanation, hope you understand... I'm not english native and I have been reading to find how to solve this, but haven't find any solution yet... thanks for any help you could give me!
regards,
Daniel
firstfile.html code:
[code]
Oper
Lote
Juliano
Fecha
Lote/Juliano Origen
Enviado
Rechazado
Validado
Recibido
Rechazo Op
Estado
Comentarios
Cargando datos del servidor
Oper
Lote
Juliano
Fecha
Lote/Juliano Origen
Enviado
Rechazado
Validado
Recibido
Rechazo Op
Estado
Comentarios
[/code]
scripts/server_processing.php code:
...
[code]
$ruta_a_joomla = "/../";
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__)."/../".$ruta_a_joomla ));
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE2', realpath(dirname(__FILE__)."/../../" ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE2 .DS.'configuration.php' );
$mainframe =& JFactory::getApplication('site'); //llama a joomla puedes poner 'admin' si quieres que valide en el back
$mainframe->initialise(); //inicio a la aplicación
$userjoomla = &JFactory::getUser(); //llamas la clase
$username = $userjoomla->username;
[/code]
...the resto of the code is the same from datatables serverside example code...
This discussion has been closed.
Replies
hope someone can help... I have been reading code for some hours.... thanks!
[code]
$userjoomla = &JFactory::getUser(); //llamas la clase
$username = $userjoomla->username;
// ... find where the filters are defined in the server processing sample file, and make username part of the default WHERE clause
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "WHERE username = '$username' ";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "AND (";
// ...
}
[/code]