Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Forum Question

    Me and my friend started to create our own php/mysql forums like phpbb but different, so far its going great but we came across this one error. This is my code
    PHP Code:
    <select name="forum_jump" onchange="jumptoforum">
    <option value="0" selected="selected">Select Forum</option>
        <?php
        $query 
    mysql_query("SELECT * FROM `cats` ORDER BY `cat_order`");
        while (
    $cats mysql_fetch_array($query)) 
        {
        
    $title $cats['cat_title'];
        
    ?>
    <option value="0">--- <?=$title ?></option>
        <?
        
    }
        
    $query2 mysql_query("SELECT * FROM `forums` WHERE `cat_id` = $cat_id ORDER BY `forum_order` DESC");
           while (
    $forums mysql_fetch_array($query2)) {
               
    $forum_id $forums['forum_id'];
               
    $forum_name stripslashes($forums['forum_name']);
               
    ?>
    <option value="<?=$forum_id ?>">|- <?=$forum_name ?></option>
               <?
                
    }
            
    ?>
    </select>
    and when i open the page it only shows the categories in the select box, not the fourms, any help would be appreciated
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Could you show us what the code outputs and what it should output?
    Where is $cat_id?
    Code:
    WHERE `cat_id` = $cat_id
    You are looping for the results but you select only a specific ID.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    heres the outputs

    about the $cat_id im going back into my file to see if its totally left out or i jus forgot to write it in my original post
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #4
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i went back and $cat_id was not there, i went ahead and added it, but it still doesn't work and this is what i got

    it should have 2 categories and 2 forums under them, but i get the 2 categories but only 1 forum under 1 category
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well the $cat_id is somewhat important... if you really have the rows with the correct category id, then the problem is most likely what value $cat_id holds. I think it should hold the value og $cats['id'] (if "id" is the right name).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i know and right now my code is:
    PHP Code:
    <select name="forum_jump" onchange="jumptoforum">
    <option value="0" selected="selected">Select Forum</option>
        <?php
        $query 
    mysql_query("SELECT * FROM `cats` ORDER BY `cat_order`");
        while (
    $cats mysql_fetch_array($query)) 
        {
        
    $title $cats['cat_title'];
        
    $cat_id $cats['cat_id'];
        
    ?>
    <option value="0">--- <?=$title ?></option>
        <?
        
    }
        
    $query2 mysql_query("SELECT * FROM `forums` WHERE `cat_id` = $cat_id ORDER BY `forum_order` DESC");
           while (
    $forums mysql_fetch_array($query2)) {
               
    $forum_id $forums['forum_id'];
               
    $forum_name stripslashes($forums['forum_name']);
               
    ?>
    <option value="<?=$forum_id ?>">|- <?=$forum_name ?></option>
               <?
                
    }
            
    ?>
    </select>
    and it only is displaying the 2 fcategories and one forum instead of 2 categories and the 2 forums under each category
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    By the way the code is indented I thought that thesecond while loop is inside the first one... That explains why the first category has no forums at all. You could generate that jumpbox like that but you should cache the result.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so should i put the forum while loop inside the category while loop?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well I assume that the `cat_id` in the `forums` table holds the category of that forum... so if you're selecting forums with a specific `cat_id` you'd have to do it for every category.
    There are ways of storing data which will require only one query to get all data (MPTT for instance).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #10
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you give me an example of a script that will show all the forums under each category?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon


  •  

    Posting Permissions

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