1

When I execute SELECT query in php in order to get data from MySQL DB into bootstrap table, the apostrophes are not displayed correctly in the table rows. In particular, I get Gr�a instead of Grúa.

This is how I get data from MySQL DB:

<?php
  include_once 'include/connect_db.php';

  $query = "SELECT * FROM myTable;";
  $result = ejecutar_query($query);

  $list = array();
  while ($b = mysqli_fetch_array($result)) {
    $list[] = $b;
  }
?>

<td><?php echo $row['name'];?></td>

<!--jQuery Datatable-->
<script>
     $(document).ready(function(){
              $('#myTable').dataTable({
              "sPaginationType":"full_numbers",
              "aaSorting":[[0, "asc"]],
              "bJQueryUI":true
              });

              hideLoading();

     });
</script>

Should I change the encoding in MySQL DB or what should I do to solve this issue?

Dinosaurius
  • 8,306
  • 19
  • 64
  • 113

2 Answers2

2

You need to encode/decode the chars in that case. Changing the charset of the table/database may cause data loss.

<td><?php echo utf8_encode($row['name']);?></td>

if utf8_encode() does not work try utf8_decode() instead.

Markus Zeller
  • 8,516
  • 2
  • 29
  • 35
0

Do not use any encode/decode functions; that just compounds the problem.

See here for discussion of the causes and cures of "black diamond".

Rick James
  • 135,179
  • 13
  • 127
  • 222