I often follow your suggestions on this forum. Now I have an issue with Datatable plugin. On my website, I have created a food table. This table takes all data from mysql database and use DataTable to have some additional plugins. The issue is that DataTable doesn't encode correctly some characters showing some "??". I saw that mysql encode is base on latin1 and not on utf8. How can I force the utf8 encoding?
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");
};
?>
Below the code created for the table:
<div style="overflow-x:auto;">
<table id="tabellaAlimenti" class="table table-striped">
<thead>
<tr>
<th>Nome</th>
<th>Categoria</th>
<th>Kcal</th>
<th>Carbo (g)</th>
<th>Prot (g)</th>
<th>Gras (g)</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM databaseAlimenti";
if ($result = mysqli_query($link, $query)) {
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td id='nome'><a href='http://wellness4yourself-com.stackstaging.com/alimento/?nome=" .urlencode($row['Nome']). "'>" . $row['Nome'] . "</a></td>";
echo "<td>" . $row['Categoria'] . "</td>";
echo "<td>" . $row['kcal'] . "</td>";
echo "<td>" . $row['Carboidrati (g)'] . "</td>";
echo "<td>" . $row['Proteine (g)'] . "</td>";
echo "<td>" . $row['Grassi totali (g)'] . "</td>";
echo "</tr>";
}
};
?>
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#tabellaAlimenti').DataTable( {
select: true,
});
});
</script>
Thanks in advance