title: How to jquery search in database after accent neutralise in datatables - not working
body: <p>Hello I have table with datatables jquery plugin. I added script in index.php in footer (pages are loaded using switch) for accent neutralising, because I want to search without diacritics. <strong>This script is not working in fields from DB</strong>, but when I added to echo new row - so in this row everything is OK.</p>
  
  <p>Here is part of my code from body:</p>
  
  <pre><code>  $stmt = sqlsrv_query( $conn, $sql );
    if( $stmt === false) {
        die( print_r( sqlsrv_errors(), true) );
    }
    echo "&lt;div class='container'&gt;
  
          &lt;h5&gt;Heading&lt;/h5&gt;
  
  
        &lt;table id='tabulka_kariet' class='table table-bordered'&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Kód karty&lt;/th&gt;
              &lt;th&gt;Názov karty&lt;/th&gt;
              &lt;th&gt;Špec 1 &lt;/th&gt;
              &lt;th&gt;Špec 2 &lt;/th&gt;
              &lt;th&gt;Špec 3 &lt;/th&gt;
              &lt;th&gt;Špec 4 &lt;/th&gt;
  
  
            &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tfoot&gt;
            &lt;tr&gt;
              &lt;th&gt;Kód karty&lt;/th&gt;
              &lt;th&gt;Názov karty&lt;/th&gt;
              &lt;th&gt;Špec 1 &lt;/th&gt;
              &lt;th&gt;Špec 2 &lt;/th&gt;
              &lt;th&gt;Špec 3 &lt;/th&gt;
              &lt;th&gt;Špec 4 &lt;/th&gt;
  
            &lt;/tr&gt;
          &lt;/tfoot&gt;
        &lt;tbody&gt;
                    &lt;tr&gt;
                &lt;td&gt;mála&lt;/td&gt;
                &lt;td&gt;očivá&lt;/td&gt;
                &lt;td&gt;lólo&lt;/td&gt;
                &lt;td&gt;šesť&lt;/td&gt;
                &lt;td&gt;nedeľa&lt;/td&gt;
                &lt;td&gt;ľščťžýáíé&lt;/td&gt;
              &lt;/tr&gt;";
  
  
     while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
    echo "&lt;tr&gt;";
  
    echo "&lt;td&gt;" . $row['Code'] . "&lt;/td&gt;";
    echo "&lt;td&gt;&lt;a href=\"detail.php?id=" . $row['Id'] . " \"&gt;" . $row['Name'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Specification'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Specification2'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Specification3'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Specification4'] . "&lt;/td&gt;";
  
    echo "&lt;/tr&gt;";
    }
    echo "&lt;/tbody&gt;&lt;/table&gt;";
  
  
     sqlsrv_free_stmt( $stmt);
  
    ?&gt;
  </code></pre>
  
  <p>Here is script from footer:</p>
  
  <pre><code>      &lt;script&gt;
        $(document).ready( function () {
        jQuery.fn.DataTable.ext.type.search.string = function ( data ) {
           return ! data ?
            '' :
            typeof data === 'string' ?
                data
                    .replace( /έ/g, 'ε' )
                    .replace( /[ύϋΰ]/g, 'υ' )
                    .replace( /ό/g, 'ο' )
                    .replace( /ώ/g, 'ω' )
                    .replace( /ά/g, 'α' )
                    .replace( /[ίϊΐ]/g, 'ι' )
                    .replace( /ή/g, 'η' )
                    .replace( /\n/g, ' ' )
                    .replace( /[áàäâ]/g, 'a' )
                    .replace( /[éÉěĚèêëÈÊË]/g, 'e')
                    .replace( /[íìïî]/g, 'i' )
                    .replace( /[óòöô]/g, 'o' )
                    .replace( /[ùüûúÚůŮ]/g, 'u' )
                    .replace( /[ľĽ]/g, 'l')
                    .replace( /[šŠ]/g, 's')
                    .replace( /[čČçÇ]/g, 'c')
                    .replace( /[řŘ]/g, 'r')
                    .replace( /[ťŤ]/g, 't')
                    .replace( /[žŽ]/g, 'z')
                    .replace( /[ýÝ]/g, 'y')
                    .replace( /[ďĎ]/g, 'd')
                    .replace( /[ňŇ]/g, 'n') :
  
                data;
    };
      var table = $('#tabulka_kariet').DataTable();
  
    } );
    &lt;/script&gt;
  </code></pre>
  
  <p>2.problem is, that This script wont function when are empty fields with spaces. So in that columns this searching is not function. Maybe there will be problem and so question is, how to prevent that from DB...? Using if condition for every field? More about this problem <a href="https://stackoverflow.com/questions/30595833/datatables-individual-column-searching-with-accent-neutralise">here</a> </p>
  
  <p>My similar <a href="https://stackoverflow.com/questions/46581962/how-to-implement-script-for-accent-neutralise-in-datatables">question</a>  few days ago
  Thanks for your answers :)</p>