Wrong interpretation of some letters from MYSQL

Wrong interpretation of some letters from MYSQL

Thepaky91Thepaky91 Posts: 4Questions: 2Answers: 0

Hello to everybody,
I have created a table that takes some data from MYSQL. I am using DataTable to customize it. The problem is that some letters aren't read in a correct way. In fact, I found "?" instead of some letters. If I create a table without using DataTable, this problem doesn't appear. How can I fix it?

thanks in advance

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It may be a character encoding issue - some difference between the DB and the web page. It would be worth confirming that they match.

    C

  • Thepaky91Thepaky91 Posts: 4Questions: 2Answers: 0

    How can I do to match the character encoding between DB and webpage? This issue only appear using DataTable. If I create a normal table without this plugin, there are no problems.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Try adding:

    $db->sql('SET NAMES utf8');
    

    immediately before your Editor::inst(...) call.

    I'm assuming you are using PHP...

    Allan

  • Thepaky91Thepaky91 Posts: 4Questions: 2Answers: 0

    Sorry, but I don't understand where I have to put it.

    Below the code for database access:

    <?php
    $link = mysqli_connect ("XXXXXXXX", 
    "XXXXX", "XXXXX", "XXXXX"); 
    
    if (mysqli_connect_error()) {
    
        die ("Problemi di connessione con il server. Riprovare più tardi");
    
    };
    
    <?php
    >
    ```
    ?>
    
    
    Below the code created for the table:
    
    
    <?php $query = "SELECT * FROM databaseAlimenti"; if ($result = mysqli_query($link, $query)) { while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "" . $row['Nome'] . ""; echo "" . $row['Categoria'] . ""; echo "" . $row['kcal'] . ""; echo "" . $row['Carboidrati (g)'] . ""; echo "" . $row['Proteine (g)'] . ""; echo "" . $row['Grassi totali (g)'] . ""; echo ""; } }; ?>
    Nome Categoria Kcal Carbo (g) Prot (g) Gras (g)
    $(document).ready(function() { $('#tabellaAlimenti').DataTable( { select: true, }); });

    ```

    Thanks in advance

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I had assumed that you were using the PHP libraries for Editor, which is why my code didn't make any sense.

    I would suggest you use the PHP mysql->set_charset() function since you are using mysqli directly.

    Allan

This discussion has been closed.