Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 1816

MySQL query result

$
0
0
Hello,

I'm new with Datatables, and I haven't figured ou how to show MySQL data in a datatable table. I'm trying to use the following code:

<html>
    <head>
        <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
        <script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.10.4.custom.min.js"></script>
        <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"/>
        <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.10.4.custom.min.css"/>
        <link rel="stylesheet" type="text/css" href="css/jquery.dataTables_themeroller.css"/>
        <style>
            #myDiv{
                width: 800px;
            }
        </style>
        <script>
    $(document).ready(function() {
	
        $('#tb_data').dataTable( {
                "bProcessing": true,
		"bServerSide": true,
                "bDeferRender": true,
                "bLengthChange": false,
                "bJQueryUI": true,
                "bAutoWidth": false,
                "sPaginationType": "full_numbers",
                "sAjaxSource": "script/get_status.php",
                "aoColumns": [
                { "mDataProp": "radar"},
                { "mDataProp": "status"},
                { "mDataProp": "aeronaves"},
                { "mDataProp": "ultima"},
                { "mDataProp": "estacao"}
                ]                
     });
        
        jQuery.fn.center = function (){
            this.css("position","fixed");
            //this.css("top", ($(window).height() / 2) - (this.outerHeight() / 2));
            this.css("left", ($(window).width() / 2) - (this.outerWidth() / 2));
            return this;
        }

        $('#myDiv').center();
        $(window).resize(function(){
        $('#myDiv').center();
        });
        
    
        
    } );
        </script>
    </head>
    <body>
        <div id="myDiv">
        <table id="tb_data">
            <thead>
                <tr>
                    <th class="ui-state-default" style="width: 50px;">Estacao</th>
                    <th class="ui-state-default" style="width: 120px;">Status</th>
                    <th class="ui-state-default" style="width: 120px;">Aeronaves</th>
                    <th class="ui-state-default" style="width: 105px;">Atualizacao</th>
                    <th class="ui-state-default" style="width: 20px;">Radar</th>
                </tr>
            </thead>
            <tbody>
                    
            </tbody>
        </table>
        </div>
    </body>
</html>

PHP code

<?php

include 'database_connection.php';

$query_names = mysqli_query($dblink, "SET NAMES 'utf8'");

$query_stat = mysqli_query($dblink, "select NodeID AS Radar, (CASE WHEN (Connected = 1) THEN 'Ativo' ELSE 'Inativo' END) AS Status, CurrentTracks AS Aeronaves, Max AS Ultima_Atualizacao, StationID AS Estacao FROM serverStat order by Status, Radar Asc");

$data = array();
if ( $query_stat && mysqli_num_rows($query_stat) )
{
    while( $row = mysqli_fetch_array($query_stat, MYSQL_ASSOC) )
    {
        $data[] = array(
            'radar' => $row['Radar'],
            'status' => $row['Status'],
            'aeronaves' => $row['Aeronaves'],
            'ultima' => $row['Ultima_Atualizacao'],
            'estacao' => $row['Estacao']
        );
    }
}

echo json_encode($data);
flush();

?>

I'm getting the error bellow:

<TypeError: i is undefined>

Any help will be appreciated. Thanks!

Marcio

Viewing all articles
Browse latest Browse all 1816

Trending Articles