New row not displayed
New row not displayed
Hi, when ever I add a new record to the datatable it doesn't display the new inserted row, insted shows the 1rst record duplicated.
Here is my php file.
<?php
/*
* Editor server script for DB table modelos
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "DataTables.php" );
include("session.php");
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'usuarios', 'usuarios.idUsuarios' )
->fields(
Field::inst( 'usuarios.usuario' )
->validator( 'Validate::notEmpty',
array(
"message" => "Campo obligatorio"
)),
Field::inst( 'usuarios.contrasena' )->set( Field::SET_CREATE ),
Field::inst( 'usuarios.idFraccionamientos' )->set( Field::SET_CREATE ),
Field::inst( 'usuarios.rol' )
->validator( 'Validate::notEmpty',
array(
"message" => "Campo obligatorio"
)),
Field::inst( 'usuarios.activo' )
->validator( 'Validate::notEmpty',
array(
"message" => "Campo obligatorio"
))
)
->on( 'preCreate', function ( $editor, $values ) {
/*Random Password*/
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyz";
return substr(str_shuffle($chars),0,$length);
}
$automatic_pass = rand_string(8);
$editor
->field( 'usuarios.contrasena' )
->setValue( $automatic_pass );
$editor
->field('usuarios.idFraccionamientos')
->setValue($_SESSION['fraccionamiento']);
} )
->where('usuarios.idFraccionamientos',$_SESSION['fraccionamiento'],'=')
->where( function ( $q ) {
$q
->and_where( 'usuarios.rol', 'Colono', '=' )
->or_where( function ( $r ) {
$r->where( 'usuarios.rol', 'Presidente' );
} );
} )
->leftJoin( 'fraccionamientos', 'fraccionamientos.idFraccionamientos', '=', 'usuarios.idFraccionamientos' )
->where('usuarios.idFraccionamientos',$_SESSION['fraccionamiento'],'=')
->process( $_POST )
->json();
Hope you can help me out.
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
Is your
idUsuarios
column set to be the primary key and also an auto incrementing sequence?Allan
Thanks for the replay. Yes, the column idUsuarios is set as primary key and is auto incrementing. Could this problem be caused by the where condition at the end of the code?
If the new row doesn't match the condition in the
where
statements, then yes, it wouldn't be visible in the table. might that be the case here with the data you are entering?Allan
I eliminate this part of the code, and it worked correctly.
How can be able to show only the records that have Colono or Presidente in the column named: rol?
should do it.
Allan