问题
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