= " . $start . " AND position <= " . $end; } $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } $num = mysql_numrows($result); // Print the header and find the sample IDs echo "chr\tpos\trsID"; $arr = mysql_fetch_assoc($result); $i = 0; foreach ($arr as $key => $value){ if ($key != "position" && $key != "rsid"){ $samples[$i] = $key; $i++; echo "\t" . $key; } } echo "\n"; // Read and print the data mysql_data_seek($result,0); while ($arr = mysql_fetch_assoc($result)){ echo $chr . "\t" . $arr['position'] . "\t" . $arr['rsid']; foreach ($samples as $field){ echo "\t".$arr[$field]; } echo "\n"; } ?>