Datatable Problem Showing 0 to 0 of 0 entries (filtered from 32 total entries)

Datatable Problem Showing 0 to 0 of 0 entries (filtered from 32 total entries)

laurent09laurent09 Posts: 18Questions: 0Answers: 0

Hi

For starters I'm sorry for my bad english, I'm french.

Here I have a problem with my datatable.

when I am on my local server everything works, my table function.
but when I put it online on my site my table does not show up
(Showing 0 to 0 of 0 entries (filtered from 32 total entries)).

I do not understand what I'm doing wrong.
why it does not appear on my web site online and why on my local website it is displayed correctly. I do not change anything, it's the same database.

my website : http://ckdn.esy.es/

Replies

  • laurent09laurent09 Posts: 18Questions: 0Answers: 0
  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @laurent09 ,

    I'd say that's pretty good English :)

    The problem is the server-side fetch.php script, it's returning this:

    {"draw":1,"recordsTotal":32,"recordsFiltered":null,"data":[]}
    

    DataTables is just displaying that. So the server-side script needs some debug, I'm afraid.

    Cheers,

    Colin

  • laurent09laurent09 Posts: 18Questions: 0Answers: 0

    thanks

    I dont understand how to debug the file fecth.php?

    I dont understand also why on my local websit it's works? while I change anything, they are the same files.

    my fetch.php

    //fetch.php

    // connection
      require_once('../includes/config.php');
      $connect = new mysqli($CONF['host'], $CONF['user'], $CONF['pass'], $CONF['name']);
      if ($connect->connect_errno) {
          echo "Failed to connect to MySQL: (" . $connect->connect_errno . ") " . $connect->connect_error;
      };
    
    $column = array("uc.date_add", "u.username", "c.category_g_name", "uc.recherche", "u.born");
    $query = "
             SELECT * FROM users U
             INNER JOIN users_category UC ON (U.idu = UC.id_users)
             INNER JOIN category_games C ON (UC.id_category = C.id)  
            ";
    $query .= " WHERE";
    $query .= " UC.recherche = 1 AND";
    
    if(isset($_POST["is_category"]))
        {
            $query .= " c.id = '".$_POST["is_category"]."' AND ";
        }
    
    if(!empty($_POST["steam"]))
        {
            $query .= " u.steam AND ";
        }
    
    if(isset($_POST["search"]["value"]))
        {
             $query .= '(uc.date_add LIKE "%'.$_POST["search"]["value"].'%" ';
             $query .= 'OR u.username LIKE "%'.$_POST["search"]["value"].'%" ';
             $query .= 'OR c.category_g_name LIKE "%'.$_POST["search"]["value"].'%" ';
             $query .= 'OR uc.recherche LIKE "%'.$_POST["search"]["value"].'%" ';
             $query .= 'OR u.born LIKE "%'.$_POST["search"]["value"].'%") ';
        }
    
    if(isset($_POST["order"]))
        {
            $query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
        }
        else
        {
            $query .= 'ORDER BY uc.date_add DESC ';
        }
    
    $query1 = '';
    
    if($_POST["length"] != 1)
        {
            $query1 .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
        }
    
    
    $number_filter_row = mysqli_num_rows(mysqli_query($connect, $query));
    
    $result = mysqli_query($connect, $query . $query1);
    
    $data = array();
    
    while($row = mysqli_fetch_array($result))
    {   
      // steam profil
        if (isset($row["steam"]))
            {
                $steam = simplexml_load_file("https://steamcommunity.com/profiles/".$row["steam"]."?xml=1", 'SimpleXMLElement', LIBXML_NOCDATA);
                $steamstatut = str_replace("<br />", " - ", $steam->onlineState);
            } else {
                $steamstatut = '';
            }
    
      // calcule age user
        $ub = explode('-', $row["born"]) ;
        $age = date('Y') - $ub[0] ;
        if ( date('md') < $ub[1].$ub[2] ) $age-- ; 
    
      //calcul nbr de our de l'annonce
        $now = new DateTime("now");
        $dateBdd = new DateTime($row["date_add"]);
      //$date_add = $dateBdd1->diff($now)->format("%d jours, %h heurs and %i minutes");
        $date_add = $dateBdd->diff($now);
        $jours = $date_add->format("%d jrs");
        $heurs = $date_add->format("%h hrs");
        $minute = $date_add->format("%i min");
        if ($jours == 0 ) {  
    
            if ($heurs == 0 ) {
                $afficher = $minute;
            }
            else {
                $afficher = $heurs;
            }
        }  else {
                $afficher = $jours;
        }
    
         $sub_array = array();
         $sub_array[] = '<th></th>';
         $sub_array[] = $afficher;
         $sub_array[] = '<a href="'.$URL = $CONF['url'].'/index.php?a=profile&u='.$row["username"].'">'.$row["username"].' </a>';
         $sub_array[] = $row["category_g_name"];
         $sub_array[] =  $age. 'ans  <a href="'.$URL.'/index.php?a=profile&u='.$row["username"].'" class="voir">+</a>';
         $sub_array[] = $steamstatut;
         $data[] = $sub_array;
    
    }
    
    function get_all_data($connect)
        {
    
             $query = "SELECT * FROM users_category";
             $result = mysqli_query($connect, $query);
             return mysqli_num_rows($result);
        }
    
    $output = array(
         "draw"    => intval($_POST["draw"]),
         "recordsTotal"  =>  get_all_data($connect),
         "recordsFiltered" => $number_filter_row,
         "data"    => $data
        );
    
    echo json_encode($output);
    

    thanks for your help

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    edited May 2018

    That's one of your scripts, so I don't know off hand. It's not permissions to the database, since it knows the number of records and returns that correctly. It's like to be something around the loop on line 59. Sorry I can't be any more use.

  • laurent09laurent09 Posts: 18Questions: 0Answers: 0
    edited May 2018

    ok i found my mistake i replaced this

    $query .= 'ORDER BY uc.date_add DESC ';

    by that
    $query .= 'ORDER BY date_add DESC ';

    and everything works fine.

    thank you very much

This discussion has been closed.