using Datatables with PHP
using Datatables with PHP
urboyfriend
Posts: 4Questions: 0Answers: 0
how do i load a table using PHP? im not sure where to go next
http://i172.photobucket.com/albums/w11/urboyfriend/symbols.jpg
[code]
<?PHP
$user_name = "root"; //connect to server
$password = "";
$database = "testdb";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$queryString = "SELECT * FROM symbols";
$result = mysql_query($queryString);
$totalRows = mysql_num_rows($result);
for ($i = 0; $i < $totalRows; ++$i) {
$postData[$i] = mysql_fetch_array($result);
}
$myJSONString = json_encode($postData);
echo $myJSONString;
?>
[/code]
http://i172.photobucket.com/albums/w11/urboyfriend/symbols.jpg
[code]
<?PHP
$user_name = "root"; //connect to server
$password = "";
$database = "testdb";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$queryString = "SELECT * FROM symbols";
$result = mysql_query($queryString);
$totalRows = mysql_num_rows($result);
for ($i = 0; $i < $totalRows; ++$i) {
$postData[$i] = mysql_fetch_array($result);
}
$myJSONString = json_encode($postData);
echo $myJSONString;
?>
[/code]
This discussion has been closed.
Replies
http://www.datatables.net/release-datatables/examples/server_side/server_side.html
this is sample.php
[code]
DataTables example
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "localhost/datatableprototype/server_processing.php"
} );
} );
DataTables server-side processing example
ID
country
animal
[/code]
i have used your link above and tried to use the code, i only edited this part
server_processing.php
[code]
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array( 'id', 'country', 'animal');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "symbols";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "testdb";
$gaSql['server'] = "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
*/
[/code]
http://i172.photobucket.com/albums/w11/urboyfriend/null.jpg
may i know what am i doing wrong? thanks!
http://i172.photobucket.com/albums/w11/urboyfriend/sp.jpg
second one reloaded browser
http://i172.photobucket.com/albums/w11/urboyfriend/sp2.jpg
Simple matter of fixing your links before proceeding further.