No data available in table
No data available in table
Baranek
Posts: 3Questions: 2Answers: 0
I try load data in to table by PHP - MySQL external file:
<?php
// datatbáza premenné
$sql_server="***";
$uzivatel="***";
$heslo="***";
$nazov_databazy="***";
$nazov_tabulky="***";
$con = mysql_connect($sql_server,$uzivatel,$heslo);
$dbs = mysql_select_db($nazov_databazy, $con);
$result = mysql_query("SELECT zak_id, zak_nazov, zak_ulica FROM zakaznici");
$json_array = array();
while ($row = mysql_fetch_assoc ($result))
{
$json_array[] = $row;
}
echo json_encode($json_array);
<?php
>
```
?>
It give data in to console as (its trying datas):
> [{"zak_id":"1","zak_nazov":"Baranek s.r.o.","zak_ulica":"Lomnick\u00e1 6"},{"zak_id":"2","zak_nazov":"sdasdasdsada","zak_ulica":"asdasdsad 4"},{"zak_id":"3","zak_nazov":"sdffsdf","zak_ulica":"sdfdsfsf"},{"zak_id":"4","zak_nazov":"scscscsdcc","zak_ulica":"sdcsdcsc"},{"zak_id":"6","zak_nazov":"ssadd","zak_ulica":"asdad"},{"zak_id":"11","zak_nazov":"cyc","zak_ulica":"yxcxyc"},{"zak_id":"12","zak_nazov":"sdfsdf","zak_ulica":"sdfdsf"},{"zak_id":"13","zak_nazov":"asdasd","zak_ulica":"asdasd"},{"zak_id":"14","zak_nazov":"ada","zak_ulica":"ada"},{"zak_id":"15","zak_nazov":"oooo","zak_ulica":"ooooo"},{"zak_id":"16","zak_nazov":"adad","zak_ulica":"asdad"}]
But I cannot see them in table. For it I use script looks like:
$(document).ready(function() {
$('#datatable-keytable').DataTable({
processing: true,
serverSide: true,
type:'Post',
url: 'php-list-zakaznik.php',
data: 'data',
dataType: 'json',
columns: [
{ data: 'zak_id' },
{ data: 'zak_nazov' },
{ data: 'zak_ulica' }
]
}
});
});
```
Thanks for help. I did it to two days without datas in table....
This discussion has been closed.
Answers
Your syntax is wrong. data: 'data' should not be there if serverSide is true. If it is not true, then data should be your json object, not a string. ServerSide:true should only be used if you have a lot of data, like over ten thousand rows, or a very slow network.
If you are sending 'data' as a parameter to the server, it should look more like
$(document).ready(function() {
});
Keep in mind that when serverSide is true, all of the paging, filtering, etc is done by the server. DataTables normally passes the object you need to figure all of this out but your use of "data":"data" would clobber this.
Thanks for your help but without success. This code show all required datas but without pagination and filetring or any table action:
- PHP file stay without changes only I read all tables tata select * from table
- js code is this by your recomandation:
But if I use this then all is function (is this code right?):
Would somebody help how I do this:
- end of script // Click on row...
- here when I click on row I need open form with datas from this selected row for change datas which I need
- after click on button save these new row datas will be replaced in database.
Thanks.