I am trying to retrieve my data from database and show it in datatables my Main function file contains a function to get specific column related to another table
if(! function_exists('get_item')){
function get_item($column,$tbl,$col_name,$id){
global $con;
$stmt = $con->prepare("SELECT $column FROM $tbl WHERE $col_name = ?");
$stmt->execute(array($id));
$row = $stmt->fetch();
if($stmt->rowCount() > 0){
return $row[$column];
}
}
}
then in users server processing file this is the code
$table = 'users';
$primaryKey = 'id';
$columns = array(
array('db' => 'id', 'dt' => 0,
'formatter' => function($d){
return "<input type='checkbox' onchange='toggleCheckbox()' name='checkUser[]' value='$d'/>";
}
),
array( 'db' => 'id', 'dt' => 1 ),
array('db' => 'avatar', 'dt' => 2,
'formatter' => function( $d) {
if($d != '')
return "<img src='../assets/uploads/users/$d' width='50' height='50' class='img-thumbnail img-responsive'/>";
else
return "<img src='../assets/uploads/users/no-img.jpg' width='50' height='50' class='img-thumbnail img-responsive'/>";
}
),
array('db' => 'username', 'dt' => 3),
array('db' => 'email', 'dt' => 4),
array('db' => 'role_id', 'dt' => 5 ,
'formatter' => function($d){
$role_name = get_item('role_name','roles','id',$d);
return $role_name;
}
),
array(
'db' => 'created_at',
'dt' => 6,
'formatter' => function( $d, $row ) {
return date( 'jS M y', strtotime($d));
}
),
array(
'db' => 'id',
'dt' => 7,
'formatter' => function ($d , $row){
return "
<a href='?do=Edit&id=$d' class='btn btn-warning'> <i class='fa fa-pen'></i></a>
<a onclick='confirmation(event)' href='?do=Delete&id=$d' class='btn btn-danger'> <i class='fa fa-trash'></i></a>
";
}
)
);
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'lineshop',
'host' => 'localhost'
);
require( '../ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
the error message is
DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
if I remove get_item function from the users server processing file it works prefect
but I need to show the role name of user
how can i fix it