There is a code
$sql_query = "SELECT * FROM(SELECT [name], [date], [status], row_number() OVER (PARTITION BY [name] ORDER BY [date] DESC) AS rownum FROM [script_monitoring].[dbo].[script_status]) [script_status] where rownum <= 10"; $params = array(); $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET); $stmt = sqlsrv_query($conn, $sql_query, $params, $options); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $data = array(); $data_names = array(); $n = 0; while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { $data[$n][$row[3]][0] = $row[0]; $data[$n][$row[3]][1] = date_format($row[1], "Ymd H:i:s"); $data[$n][$row[3]][2] = $row[2]; $data_names[$n] = $row[0]; //$data = array( // [$n] => array( // [$row[3]] => array($row[0], date_format($row[1], "Ymd H:i:s"), $row[2] // ) // ) // ); $n++; } sqlsrv_free_stmt($stmt); sqlsrv_close($conn); $unique_script_names = array_unique($data_names); echo "<ul class=\"main_table\">"; foreach ($unique_script_names as $script_name) { echo "<li><table id=\"" . $script_name . "\"class=\"script_table\">"; echo "<thead>"; echo "<tr>"; echo "<th colspan=\"4\">" . $script_name . "<span class=\"close_table_button\"><span class=\"ui-icon ui-icon-close\"></span></span></th>"; echo "</tr>"; echo "<tr>"; echo "<th>имя</th>"; echo "<th>дата</th>"; echo "<th>статус</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; $n = 0; $n2 = 1; foreach ($data[$n] as $data_row) { echo "<tr>"; foreach ($data_row[$n2] as $value) { echo "td" . $value . "</td>"; } echo "</tr>"; $n++; $n2++; } echo "</tbody>"; echo "</li>"; } echo "</ul>"; Interested in the last part, how to display the array?