so to better describe my problem :
1- i aquire data from Mysql database
2- I organise it into my Html Table with an id of : id="#Elements"
while ($row = $result->fetch_assoc()) {
echo('<tr>');
echo '<td>'.$row["Rang"].'</td>';
echo '<td>'.$row["Pays"].'</td>';
echo '<td>'.$row["Region"].'</td>';
echo '<td>'.$row["Documents"].'</td>';
echo '<td>'.$row["Documents_citables"].'</td>';
echo '<td>'.$row["Citations"].'</td>';
echo '<td>'.$row["Autocitations"].'</td>';
echo'<td>'.$row["Citations_par_document"].'</td>';
echo '<td>'.$row["Indiceh"].'</td>';
echo '<td>'.$row["Discipline"].'</td>';
echo '<td>'.$row["Sous_discipline"].'</td>';
echo '<td>'.$row["Annee"].'</td>';
echo( '</tr>');
}
3- In my js file , i tried to convert this table to Csv using these two functions :
function exportTableToCSV(filename) {
    var csv = [];
    var rows = document.querySelectorAll("table tr");
    
    for (var i = 0; i < rows.length; i++) {
        var row = [], cols = rows[i].querySelectorAll("td, th");
        
        for (var j = 0; j < cols.length; j++){
            row.push(cols[j].innerText);
            console.log(cols[j].innerText);
        }
        
        csv.push(row.join(","));        
    }
    // Download CSV file
    downloadCSV(csv.join("\n"), filename);
}
function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;
    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});
    // Download link
    downloadLink = document.createElement("a");
    // File name
    downloadLink.download = filename;
    // Create a link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);
    // Hide download link
    downloadLink.style.display = "none";
    // Add the link to DOM
    document.body.appendChild(downloadLink);
    // Click download link
    downloadLink.click();
}
For the button that calls the function :
<button id="download-csv" class="downloadcsv" onclick="exportTableToCSV('data.csv');">Télécharger le tableau</button>
4- i get a CSV file but with unreadable text, for example : Région is shown as Région
My html file is set to Charset UTF-8 and my database is also using default characters in it's settings
Can anyone help me figure out how to fix this issue, or even how to Convert the table to csv in a "cleaner" way. thank you
Note : im only using php and js for this project .
