Big data, slow

Big data, slow

malcolm-xmalcolm-x Posts: 5Questions: 1Answers: 0
edited December 2016 in Free community support

Hello, I do not speak English!

I use Datatables.net, thank you very much.
But I have a problem!
For very loaded data, the page load time is long, the problem occurs when the page loads, the slowness of the page loading.

How can I solve this problem?

I did not understand that !
https://datatables.net/examples/server_side/simple.html

Do you have a sample file?

thank you very much

Answers

  • malcolm-xmalcolm-x Posts: 5Questions: 1Answers: 0

    I translated it with google. can you help me ?
    I have not received the answer before!
    Http://uzmancevap.org/soru/7713/datatables-jquery-yavaslik-sorunu-hk
    I use php

  • malcolm-xmalcolm-x Posts: 5Questions: 1Answers: 0

    example;
    index.php page

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Ahmet</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">

    <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    
    $(document).ready(function() { $('#example').DataTable( { "processing": true, "serverSide": true, "ajax": "ajaxdeneme.php" } ); } );

    <style type="text/css">
    .ahmet{
    width: 800px;
    margin: auto;
    margin-top: 60px;
    }
    </style>
    </head>
    <body>
    <div class="ahmet">

    <!-- Tablo Başlama Alanı -->
    <table id="example" class="display" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>First name</th>
                        <th>Last name</th>
                        <th>Position</th>
                        <th>Office</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>First name</th>
                        <th>Last name</th>
                        <th>Position</th>
                        <th>Office</th>
                    </tr>
                </tfoot>
            </table>
        <!-- Tablo Bitiş Alanı -->
    

    </div>
    </body>
    </html>

    ajaxdeneme.php page
    <?php
    /**
    * Script: DataTables server-side script for PHP 5.2+ and MySQL 4.1+
    * Notes: Based on a script by Allan Jardine that used the old PHP mysql_* functions.
    * Rewritten to use the newer object oriented mysqli extension.
    * Copyright: 2010 - Allan Jardine (original script)
    * 2012 - Kari Söderholm, aka Haprog (updates)
    * License: GPL v2 or BSD (3-point)
    */
    mb_internal_encoding('UTF-8');

    /**
    * 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( 'ahm_id', 'ahm_adsoyad', 'ahm_yasi', 'ahm_dogumyeri');

    // Indexed column (used for fast and accurate table cardinality)
    $sIndexColumn = 'ahm_id';

    // DB table to use
    $sTable = 'tablomuzburda';

    // Database connection information
    $gaSql['user'] = 'alibaba';
    $gaSql['password'] = 'ahmet123';
    $gaSql['db'] = 'deneme_tables';
    $gaSql['server'] = 'localhost';
    $gaSql['port'] = 3306; // 3306 is the default MySQL port

    // Input method (use $_GET, $_POST or $_REQUEST)
    $input =& $_GET;

    /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP server-side, there is
    * no need to edit below this line
    */

    /**
    * Character set to use for the MySQL connection.
    * MySQL will return all strings in this charset to PHP (if the data is stored correctly in the database).
    */
    $gaSql['charset'] = 'utf8';

    /**
    * MySQL connection
    */
    $db = new mysqli($gaSql['server'], $gaSql['user'], $gaSql['password'], $gaSql['db'], $gaSql['port']);
    if (mysqli_connect_error()) {
    die( 'Error connecting to MySQL server (' . mysqli_connect_errno() .') '. mysqli_connect_error() );
    }

    if (!$db->set_charset($gaSql['charset'])) {
    die( 'Error loading character set "'.$gaSql['charset'].'": '.$db->error );
    }

    /**
    * Paging
    */
    $sLimit = "";
    if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
    $sLimit = " LIMIT ".intval( $input['iDisplayStart'] ).", ".intval( $input['iDisplayLength'] );
    }

    /**
    * Ordering
    */
    $aOrderingRules = array();
    if ( isset( $input['iSortCol_0'] ) ) {
    $iSortingCols = intval( $input['iSortingCols'] );
    for ( $i=0 ; $i<$iSortingCols ; $i++ ) {
    if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
    $aOrderingRules[] =
    "".$aColumns[ intval( $input['iSortCol_'.$i] ) ]." "
    .($input['sSortDir_'.$i]==='asc' ? 'asc' : 'desc');
    }
    }
    }

    if (!empty($aOrderingRules)) {
    $sOrder = " ORDER BY ".implode(", ", $aOrderingRules);
    } else {
    $sOrder = "";
    }

    /**
    * Filtering
    * NOTE this does not match the built-in DataTables filtering which does it
    * word by word on any field. It's possible to do here, but concerned about efficiency
    * on very large tables, and MySQL's regex functionality is very limited
    */
    $iColumnCount = count($aColumns);

    if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
    $aFilteringRules = array();
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
    if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
    $aFilteringRules[] = "".$aColumns[$i]." LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
    }
    }
    if (!empty($aFilteringRules)) {
    $aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
    }
    }

    // Individual column filtering
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
    if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
    $aFilteringRules[] = "".$aColumns[$i]." LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
    }
    }

    if (!empty($aFilteringRules)) {
    $sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
    } else {
    $sWhere = "";
    }

    /**
    * SQL queries
    * Get data to display
    */
    $aQueryColumns = array();
    foreach ($aColumns as $col) {
    if ($col != ' ') {
    $aQueryColumns[] = $col;
    }
    }

    $sQuery = "
    SELECT SQL_CALC_FOUND_ROWS ".implode(", ", $aQueryColumns)."
    FROM ".$sTable."".$sWhere.$sOrder.$sLimit;

    $rResult = $db->query( $sQuery ) or die($db->error);

    // Data set length after filtering
    $sQuery = "SELECT FOUND_ROWS()";
    $rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
    list($iFilteredTotal) = $rResultFilterTotal->fetch_row();

    // Total data set length
    $sQuery = "SELECT COUNT(".$sIndexColumn.") FROM ".$sTable."";
    $rResultTotal = $db->query( $sQuery ) or die($db->error);
    list($iTotal) = $rResultTotal->fetch_row();

    /**
    * Output
    */
    $output = array(
    "sEcho" => intval($input['sEcho']),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData" => array(),
    );

    while ( $aRow = $rResult->fetch_assoc() ) {
    $row = array();
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
    if ( $aColumns[$i] == 'version' ) {
    // Special output formatting for 'version' column
    $row[] = ($aRow[ $aColumns[$i] ]=='0') ? '-' : $aRow[ $aColumns[$i] ];
    } elseif ( $aColumns[$i] != ' ' ) {
    // General output
    $row[] = $aRow[ $aColumns[$i] ];
    }
    }
    $output['aaData'][] = $row;
    }

    echo json_encode( $output );

    error
    http://i.hizliresim.com/5LGYJj.png

  • malcolm-xmalcolm-x Posts: 5Questions: 1Answers: 0

    What should I do? Please :(

  • malcolm-xmalcolm-x Posts: 5Questions: 1Answers: 0
  • allanallan Posts: 63,096Questions: 1Answers: 10,390 Site admin

    Use the ssp.class.php file from here. The other files show examples of how it that class can be used.

    Allan

This discussion has been closed.