When reading and displaying data which is in cyrilic from a Microsoft SQL Server, PHP fails to display it correctly. You can see part of the text displayed (only the non cyrilic stuff)
Here is what I have tried:
- setting the values in the table nchar, varchar, text and char
- adding a utf-8 tag in the html code
- using the PHP driver for SQL with the ODBC driver
- tried these collations: Cyrillic_General_100_CI_AI_SC_UTF8, cyrillic general with utf-8 and the windows code page (1251) with cyrillic general
<html>
<style>
table { width: 20em; border-collapse: collapse; }
th {
border-bottom: 2px solid #000;
padding: 0.5em 0 0.1em 0;
font-size: 1.2em;
}
td {
border-bottom: 2px solid #ccc;
padding: 0.5em 0 0.1em 0;
}
th:nth-child(n + 2),
td:nth-child(n + 2) {
text-align: center;
}
[data-has-link="no"] { background-color: #F77; }
[data-has-link="yes"] { background-color: #7F7; }
#score, #name { width: 50%; }
</style>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="jo.js"></script>
<title>AV.31.U</title>
</head>
<body>
<table style="width: 100%; height:50%" border="1" cellpadding="3">
<caption>AV.31.U</caption>
<thead>
<tr>
<td><div id="current_date"></p>
<script>
$(function() {
var $table = $('table');
$table.find('#current_date').text(getCurrentDate());
colorRows($table); // Color the rows!
});
function getCurrentDate () {
return new Date().toLocaleDateString('en-GB', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
});
}
function colorRows($table) {
var hasLink;
$table.find('tbody > tr').each(function(rowIndex) {
const $row = $(this);
$row.find('td').each(function(colIndex) {
const $cell = $(this).removeAttr('data-has-link');
const cellValue = $cell.text().trim();
if (isFinite(cellValue)) {
// Color cell based on individual data
const hasLink = cellHasLink(parseInt(cellValue, 10));
if (hasLink !== 'maybe') {
$cell.attr('data-has-link', hasLink);
}
}
});
// Color row based on 7th column
var i = parseInt($row.find('td:nth-child(7)').text(), 10);
$row.attr('data-has-link', cellHasLink(i));
});
}
function cellHasLink(value) {
switch (value) {
case 0 : return 'no';
case 1 : return 'yes';
default : return 'maybe';
}
}
</script></td>
<td colspan="6">Home</td>
<td> </td>
</tr>
<tr>
<th>Наименование</th>
<th>Описание</th>
<th>Версия</th>
<th>Верс. опис.</th>
<th>Модел</th>
<th>Видео</th>
<th>Видео отвори</th>
<th>Снимк.</th>
<th>Снимк. отвори</th>
<th>Специф.</th>
<th>Специф. отвори</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = 'censored';
$password = 'censored';
$servername = 'censored';
$database = 'SQL_KASI';
ini_set('display_errors', '1');
error_reporting(E_ALL);
$db = odbc_connect("Driver={SQL Server};Server=$servername;Database=$database;", $username, $password) or die ("could not connect<br />");
$stmt = "Select * from machine_vertical";
$result = odbc_exec($db, $stmt);
if ($result == FALSE) die ("could not execute statement $stmt<br />");
while (odbc_fetch_row($result)) // while there are rows
{
print "<tr>\n";
print " <td>" . odbc_result($result, "mach_name") . "\n";
print " <td>" . odbc_result($result, "mach_descr") . "\n";
print " <td>" . odbc_result($result, "mach_version") . "\n";
print " <td>" . odbc_result($result, "mach_version_descr") . "\n";
print " <td>" . odbc_result($result, "mach_model") . "\n";
print " <td>" . odbc_result($result, 'mach_video_yn') . "\n";
print " <td>" . odbc_result($result, "mach_video_open") . "\n";
print " <td>" . odbc_result($result, "mach_pic_yn") . "\n";
print " <td>" . odbc_result($result, 'mach_pic_open') . "\n";
print " <td>" . odbc_result($result, "mach_spec_yn") . "\n";
print " <td>" . odbc_result($result, "mach_spec_open") . "\n";
print "</tr>\n";
}
odbc_free_result($result);
odbc_close($db);
?>
</tr>
</tbody>
</table>
</body>
</html>