Thanks Steven, but I don't think this will work. The way you wrote it, for N possible catagories, there are actually 1+N database queries! (one for the array of categories and then one for articles in each catagory inside the first loop).
Right now I am fooling with the following code:
$query = "SELECT article_id, name, link, category FROM article ORDER BY category";
$result = DB_Query("content", $query);
// done once to figure out the first category returned
$temp_category = mysql_fetch_array($result[0][3]);
while ($r = mysql_fetch_array($result)) {
echo "<p>$r[category]\n";
echo "<ul>\n";
if ($r['category'] == $temp_category) {
// this loop accounts for internal vs external articles
if ($r['link'] != "") {
echo "<li><a href=\"$r[link]\">$r[name]</a>\n";
} else {
echo "<li><a href=\"$PHP_SELF?article_id=$r[article_id]\">$r[name]</a>\n";
}
}
echo "</ul>\n";
$temp_category = $r['category'];
}
The line "$temp_category = mysql_fetch_array($result[0][3]);" does not work (I haven't figured out how to do this sort of thing yet) but I think that it should be able to work in one query.
If it HAS to be two queries to work, I suppose it would have to be done like you specified but get the listings of the catagories in one query, the full listings of everything in a second query and then use some sort of find-the-intersection-of-two-arrays function to print out the second array sorted by the first.
Thanks again for your help and for any other ideas you might have.
- Erik