SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have a database called faq which has two tables:

    faq
    -------
    faq
    -ID
    -Question
    -Answer
    -Category

    category
    -ID
    -Name

    What i want is to display something like this:

    Category 1's Name
    - FAQs in this category
    -More FAQs in this toopic

    Category 2's Name
    -FAQs in the category
    -More FAQs in the category

    etc...

    How would i do this... BTW, i only want to show the titles of the FAQs. They link to listing.php which shows a list of every FAQ in a topic.

    So if Category 1 had an ID of 1 then in listing the url is: listing.php?id=1.

    Each, faq has the <a name="$id"></a> and the links to each individual Faq have <a href="#1">$question</a>

    can anyone body help me to do this? I only need the first page done. The one display all categories with their FAQs under each other.

    Thanx

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by petesmc
    Category 1's Name
    - FAQs in this category
    -More FAQs in this toopic

    Category 2's Name
    -FAQs in the category
    -More FAQs in the category
    Looks fairly straightforward. Tell me, what's the difference between "FAQs in this category" and "More FAQs in the category?"? I don't understand the distinction.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry if that wasn't clear i just meant:

    Faq number 1
    faq number 2
    etc..

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx allot for that...It worked almost flawless..

    There was a period (.) missing at the end of this statement:


    "C.ID as cid, C.Name as catname "


    Thanx

    Peter

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just trying to keep you on your toes.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •