SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make categories and forum appear

    I'm asking about making forums appear under the right categories.

    right now I'm thinking:

    PHP Code:
    $r="select * from categories"
    $r2=mysql_query($r); 
    while(
    $r3=mysql_fetch_array($r2)) 

      
    //print category here 
      
    $s="SELECT * from forums where catparent='$r3[category']"
    $s2=mysql_query($s); 
    while (
    $s3=mysql_fetch_array($s2)) 
      { 
          
    //print forum name here 
      


    Now this would work but if there are alot of categories, it takes alot of queries. Do they do it this way or do that do it some other way and select categories and forum at once and merge it together with a join statement?

  2. #2
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is not much different to these but you could try it and check which loads better.

    PHP Code:
    $r mysql_query("select * from categories"); 
    while(
    $r2 mysql_fetch_array($r)){ 
    //print category here 
    $s mysql_query("SELECT * from forums where catparent='$r2[category]'");
    while(
    $s2 mysql_fetch_array($s)){ 
    //print forum name here 



  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would strongly suggest giving your variables more meaningful names. It will help with readability and maintenance.
    John

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, that was just an example, I use pretty good variables in my real programming.

  5. #5
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gotcha!
    John


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
  •