Okay, in that case it's pretty simple. See inline comments:
Code:
<?
// Connect to the database...
...
// Begin by fetching the FAQ's, sorted by Category ID
$sql = "SELECT F.ID as id, F.Question as question, ".
"C.ID as cid, C.Name as catname ".
"FROM faq as F, category as C ".
"WHERE F.Category = C.ID ".
"ORDER BY cid";
$faqs = mysql_query($sql)
or die("Error fetching FAQ listing. Please try again later.");
// Loop through the results
while ($faq = mysql_fetch_array($faqs)) {
// Check if we're starting a new category
$catID = $faq["cid"];
if ($catID != $oldCatID) {
// Display new category name
$catName = $faq["catname"];
echo("<H4>$catName</H4>");
}
// Record the current category for the next time
$oldCatID = $catID;
// Display the current FAQ
$id = $faq["id"];
$question = $faq["question"];
echo("<P><A HREF='listing.php?id=$catID#$id'>$question</A>");
}
?>
<Edited by kyank on 01-21-2001 at 03:51 PM>
Bookmarks