query("$inject"); if(!$result) { die("Empty result!"); } else { $t_mas = []; $v_mas = []; $i = -1; $ind = -1; $test = mysqli_fetch_array($result,MYSQLI_ASSOC); mysqli_data_seek($result, 0); if ($test['Num'] != NULL) { while($myrow = mysqli_fetch_array($result,MYSQLI_ASSOC)) { if($myrow['Num'][0] != $ind) { $i++; $ind = $myrow['Num'][0]; $t_mas[$i] .= 'Session number'.';'.$myrow['Type'].';'; $v_mas[$i] .= $myrow['Num'][0].';'.$myrow['Value'].';'; } else { $t_mas[$i] .= $myrow['Type'].';'; $v_mas[$i] .= $myrow['Value'].';'; } } for($n=0; $n < count($t_mas); $n++) { $text .= $t_mas[$n]."\r\n".$v_mas[$n]."\r\n\r\n"; } } else { $cnt = 1; while($myrow = mysqli_fetch_array($result,MYSQLI_ASSOC)) { foreach ($myrow as $key => $value) { if($cnt = 1){$title .= $key.';';} $v_string .= $value.';'; } $v_string .= "\r\n"; } $text = $title."\r\n".$v_string."\r\n\r\n"; } echo $text; } } mysqli_close($mysqli); ?>