Welchen Teil des Problems löst das Folgende nicht?
<?php
include('path/to/connection/statme.nts');
$query = "
SELECT id_u
, id_k
, k
FROM dt_table
ORDER
BY id_u
, id_k;
";
$result = mysqli_query($conn,$query);
$array = array();
while($row = mysqli_fetch_assoc($result)){
$array[] = $row;
}
$new_array = array();
foreach($array as $v){
$new_array[$v['id_u']][] = $v['k'];
}
print_r($new_array);
?>