Perhaps I could do something like this:
$query = "SELECT cTitle, cID FROM tblCatagories ORDER BY cTitle";
$query2 = "SELECT tTitle FROM tblTopics WHERE c_ID='$id' ORDER BY tTitle";
<?php showCategories($query, $query2); ?>
And this would be my function:
function showCategories($query, $query2) {
$result = mysql_query($query) or die("Query failed: " . mysql_error());
while (list($cTitle, $id) = mysql_fetch_row($result)) {
echo "$cTitle\n<ol>";
$result2 = mysql_query($query2) or die("Query failed: " . mysql_error());
while (list($tTitle) = mysql_fetch_row($result2)) {
echo "<li>$tTitle</li>\n";
}
echo "</ol>\n\n";
}
}
The problem with this is the hard coded references to the table fields in the while loops and echo statements. Also, I would like to seperate the code so that the echo statements were removed somehow. For the code without the function I did as follows:
$query = "SELECT cTitle, cID FROM Categories ORDER BY cTitle";
$result = mysql_query($query) or die("Query failed: " . mysql_error());
while (list($cTitle, $id) = mysql_fetch_row($result)) { ?>
<h2><? echo $cTitle ?></h2>
<?
$query2 = "SELECT tTitle FROM Topics WHERE c_ID='$id' ORDER BY tTitle";
$result2 = mysql_query($query2) or die("Query failed: " . mysql_error());
while (list($tTitle) = mysql_fetch_row($result2)) { ?>
<a href="filesize.php"><? echo $tTitle ?></a><br />
<?
}
}
?>