Трудно для вашего кодирования различать 0 и 1. Например, как вы представляете 3015?
Однако для 1-9 достаточно кода:
print(''.join(str(len(i)) for i in enc_str.split('~')))
Выход:
1315
Если вы измените свои клавиши на это:
dnory = {'0': '~', '1': '~`', '2': '~``', '3': '~```', '4': '~````', '5': '~`````', '6': '~``````', '7': '~```````', '8': '~````````', '9': '~`````````'}
... есть способ заставить его работать так:
enc_str= "~```~`~`````"
print(''.join(str(len(i)) for i in enc_str.split('~')))
Выход:
0315
измените свой sql следующим образом
$sql = "SELECT sum(col_1) as col_1_sum ,sum(col_2) as col_2_sum, sum(col_3) as col_3_sum FROM table_1";
и выберите
while($rows = mysqli_fetch_assoc($run)){
$col[1] = $rows['col_1_sum']; // in here its better to start this $col[] array's index from 0
$col[2] = $rows['col_2_sum'];
$col[3] = $rows['col_3_sum'];
}
или как этот массив $ col, начинающийся с 0-го индекса
while($rows = mysqli_fetch_assoc($run)){
$col[0] = $rows['col_1_sum']; // in here its better to start this $col[] array's index from 0
$col[1] = $rows['col_2_sum'];
$col[2] = $rows['col_3_sum'];
}