rendering problem : does not display the same thing everytime

rendering problem : does not display the same thing everytime

trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2
edited July 2016 in Free community support

Hello,

I'm using DataTable 1.10.7 and I have a very strange problem : when I load the page, causing the datatable being populated using ajax / php / mysql, a cell is sometimes 0 and sometimes gets the correct value (which is "YES")... If a reload the page like 10 times in my browser, I will get about 7 times an incorrect value ("NO") and about 3 times the correct value ("YES").

I tested my SELECT query in PHPMyAdmin : it always get the same answer. I tested it 50 times at least. So this is not a query problem... But I don't understand what could cause this variation on the displayed value. Because the problem occurs only with a column and not all columns...

Here is what I do (briefly) in my scripts. Maybe you will see the problem easily... :-s Many thanks in advance for your help, whatever !

on $(document).ready() event on my page, I initialize DataTable using :

var tableMDS = $("#tableMDS").DataTable( {
        responsive: true,
        "autoWidth": false,
        "pageLength": 10,
        "order": [ 1, 'asc' ],
        "language": {
                "url": "bootstrap/dataTables.fr_FR.json"
            },
        "columns": [{ name: 'id', visible: true },
                    {name: 'nom'},
                    {name: 'option', width:50},
                    {name: 'statut', visible:true, "orderable": false}]
    } );

================================================

Then I load data using an $.ajax() call :

$.ajax({         
      type : 'GET',
      url: 'scripts/dbscript.php',                  
      data: "operation=list",                     
      dataType: 'json',                
      success: function(response)     
      { 
        tableMDS.clear();
        
        $.each(response, function(idx, obj) {
                        
            var statut="";          
            
            switch (obj["decision_statut"]){
                case "0" : statut="YES";break;
                case "1" : statut="NO";break;           
            }
            
            tableMDS.row.add([  obj["id"], 
                                    obj["option"],
                                    obj["name"], 
                                    statut]);     // <<<<<< THE PROBLEM OCCURS WITH THIS COLUMN
         });
         tableMDS.draw();

================================================

Here is the dbscript.php script :

$operation=$_GET['operation'];
if ($operation=="list"){        
    $db=mysql_connect(localhost,USERNAME,PASSWORD);
    mysql_select_db(DATABASE,$db) or die( "Unable to select database");
    mysql_query("SET NAMES 'utf8'");
    $query =    "SELECT id, name, option, decision_statut
                FROM listeMDS
                ORDER BY name";
    $result=mysql_query($query);
    $dataArray = array();
    while($array = mysql_fetch_assoc($result)){
        $dataArray[] = $array;
    } 
    mysql_close();
    echo json_encode($dataArray);
}

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    We'd really need a link to the page showing the issue, per the forum rules, please. I don't immediately see anything wrong with the above.

    Allan

This discussion has been closed.