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 2 of 2

Thread: Forum problem

  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts

    Forum problem

    Hello im trying to make a forum, for the front page im trying to make it display a catergory with its forums.

    here is my code

    PHP Code:
    <?php
    require './connect.php';

    if(!
    $con){
        die(
    'Could not connect: ' mysql_error());
    }

    session_start(); // Starts the session.
    if ($_SESSION['logged'] != 1) { // There was no session found!
        
    header("Location: login.php"); // Goes to login page.
        
    exit(); // Stops the rest of the script.
    }
    $tbl_name="forums";
    $tbl_name2="config";
    mysql_connect("$dbhost""$dbuser""$dbpass")or die("cannot connect");
    mysql_select_db("$dbname")or die("cannot select DB");


    $sql2="SELECT * FROM $tbl_name2";
    $sql3="SELECT * FROM $tbl_name WHERE forum_type='1'";
    // OREDER BY id DESC is order result by descending

    $result2=mysql_query($sql2);
    $result3=mysql_query($sql3);
    $rows2=mysql_fetch_array($result2);
    $rows3=mysql_fetch_array($result3);
    ?>
    <p align="center"><? echo $rows2['forumname']; ?></p>
    <? 
    while($rows3=mysql_fetch_array($result3)){
    ?>
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <td width="53%" align="center" bgcolor="#E6E6E6"><strong><?php echo $rows3['forum_name']; ?></strong></td>
    </tr>

    <?php
    $parent_id
    =$rows3['id'];
    $sql="SELECT * FROM $tbl_name WHERE forum_type='0' AND parent_id='$parent_id' ORDER BY id DESC";
    $result=mysql_query($sql);
    while(
    $rows=mysql_fetch_array($result)){ // Start looping table row
    ?>
    <tr>
    <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><a href="view_forum.php?id=<? echo $rows['id']; ?>"><? echo $rows['forum_name']; ?></a><BR></td>
    </tr>

    <?php
    }
    ?>
    </table>
    <?
    }
    ?>
    All it does is at the moment is display one of the catergory's with its child forums but not the second.

    Here is my MYSQL structure.

    Table structure for table forums
    Field Type Null Default
    id int(4) No
    parent_id int(4) No 0
    forum_name varchar(32) No
    forum_type tinyint(4) No 0



    1 3 Test 0
    2 0 Test Catergory 1
    3 0 Test cat 2 1
    7 2 Forum1 0


    forum_type 1 = Catergory
    forum_type 0 = Forum


    Any help would be great.

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    anyone have any solutions?


  •  

    Posting Permissions

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