Something that follows this logic. The trick is for each row of your result set, test whether the section name needs to be printed (because it is a different section name to the last record).
PHP Code:
// assume that a database connection already exists
$sql = "SELECT Sections.name AS sectionName,
Articles.name AS articleName
FROM Section, Article
WHERE Articles.section = Sections.id
ORDER BY sectionName, articleName";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result) {
// chech whether we need to display a new sectionName
if ( $row["sectionName"] != $currentName ) {
echo "<b>$sectionName</b><br>";
$currentName = $sectionName;
}
// display the articleName
echo "$articleName <br>";
}
Bookmarks