The apostrophes are not displayed when getting data from MySQL into bootstrap table

♀尐吖头ヾ 提交于 2020-01-15 11:04:27

问题


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?


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/44343937/the-apostrophes-are-not-displayed-when-getting-data-from-mysql-into-bootstrap-ta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!