I using datatable to show whole table of database data in it

I using datatable to show whole table of database data in it

sagarbabusagarbabu Posts: 1Questions: 1Answers: 0

Its my code:
<?php

/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simply to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See http://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - http://datatables.net/license_mit
*/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/

// DB table to use
$table = 'offers';

// Table's primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The db parameter represents the column name in the database, while the dt
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'name', 'dt' => 1 ),
array( 'db' => 'details', 'dt' => 2 ),
array( 'db' => 'contactNumber', 'dt' => 3 ),
array( 'db' => 'location', 'dt' => 4 ),
array( 'db' => 'logo', 'dt' => 5 ),
array( 'db' => 'cover', 'dt' => 6 ),
array( 'db' => 'startDate', 'dt' => 7 ),
array( 'db' => 'endDate', 'dt' => 8 ),
array( 'db' => 'category', 'dt' => 9 ),
array( 'db' => 'more_to_enjoy', 'dt' => 10 ),
/array(
'db' => 'start_date',
'dt' => 4,
'formatter' => function( $d, $row ) {
return date( 'jS M y', strtotime($d));
}
),
array(
'db' => 'salary',
'dt' => 5,
'formatter' => function( $d, $row ) {
return '$'.number_format($d);
}
)
/
);

// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'bitmoon',
'host' => 'localhost'
);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/

require( 'ssp.class.php' );

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

<?php > <!DOCTYPE html> Datatable
id name details contactnumber location logo cover startDate endDate category more_to_enjoy
id name details contactnumber location logo cover startDate endDate category more_to_enjoy
$(document).ready(function() { $('#example').DataTable( { "processing": true, "serverSide": true, "ajax": "data/arrays.txt" } ); } ); /* $('#example').dataTable( { "language": { "emptyTable": "No data available in table" } } );*/ ?>

</body>
</html>

Note: it is showing no data available in table

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Also worth asking if you actually need server-side processing. Are you using tens of thousands or more records?

    Allan

This discussion has been closed.