['min' => '-', 'max' => '-', 'avg' => '-'], 'input' => ['min' => '-', 'max' => '-', 'avg' => '-'], 'output' => ['min' => '-', 'max' => '-', 'avg' => '-'] ]; if ($table && preg_match('/^[a-zA-Z0-9_]+$/', $table)) { $sql = "SELECT MIN(CHAR_LENGTH(instruction)) as min_instruction, MAX(CHAR_LENGTH(instruction)) as max_instruction, AVG(CHAR_LENGTH(instruction)) as avg_instruction, MIN(CHAR_LENGTH(input)) as min_input, MAX(CHAR_LENGTH(input)) as max_input, AVG(CHAR_LENGTH(input)) as avg_input, MIN(CHAR_LENGTH(output)) as min_output, MAX(CHAR_LENGTH(output)) as max_output, AVG(CHAR_LENGTH(output)) as avg_output FROM `$table`"; $res = mysqli_query($conn, $sql); if ($res && $row = mysqli_fetch_assoc($res)) { $result['instruction'] = [ 'min' => $row['min_instruction'] !== null ? $row['min_instruction'] : '-', 'max' => $row['max_instruction'] !== null ? $row['max_instruction'] : '-', 'avg' => $row['avg_instruction'] !== null ? round($row['avg_instruction'], 2) : '-' ]; $result['input'] = [ 'min' => $row['min_input'] !== null ? $row['min_input'] : '-', 'max' => $row['max_input'] !== null ? $row['max_input'] : '-', 'avg' => $row['avg_input'] !== null ? round($row['avg_input'], 2) : '-' ]; $result['output'] = [ 'min' => $row['min_output'] !== null ? $row['min_output'] : '-', 'max' => $row['max_output'] !== null ? $row['max_output'] : '-', 'avg' => $row['avg_output'] !== null ? round($row['avg_output'], 2) : '-' ]; } } header('Content-Type: application/json'); echo json_encode($result);