Hi,
Why don't you try seperating the process into 2 queries. The first could look for all the headings, and then for each heading a new query is run to get the subheadings for that heading.
$sql = "SELECT * FROM header WHERE job_number=$job_number";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
for($i = 0; $i < $numrows; $i++) {
// Print this header (you could always add it to an array here, or anything else for that matter)
print mysql_result($result, $i, "hdr_text")."<br>\n";
// Get the header id
$cur_headerid = mysql_result($result, $i, "hdr_id");
// Grab the files with this id
$sql = "SELECT * FROM files WHERE hdr_id=$cur_headerid AND job_number=$job_number";
$result2 = mysql_query($sql);
$numrows2 = mysql_num_rows($result2);
for($j = 0; $j < $numrows2; $j++) {
// Print the subheading with indenting
$cur_subtext = mysql_result($result, $j, "file_text");
print " - $cur_subtext<br>\n";
}
}
Hope that makes sense, it's not incredibly elegent, but it'll work and the logic's quite nice (it won't fall on it's arse if theres no subheadings for a heading, for example).
Dom
🙂