custom coded forums, in development...

Discussion in 'Web Design & Programming' started by Waffle, Jan 13, 2006.

  1. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    I've been working on this for a while, and have nearly finished.

    Only one slight problem heh.

    I'm trying to code it so as all the forums, and all the threads, and the thread selected can be displayed all on one page.

    If that doesn't make much sense, like this:

    User accesses forums.php and views all forums in database.

    Clicks a forum, and the link is forums.php?id=$forumid

    This then refreshes the page but instead of showing forums it shows threads within that forum.

    Then, a thread is chosen, and the link becomes forums.php?id=$forumid&thread=$threadid

    However, it doesn't refresh and display that thread, unfortunately.

    I'm using IF/Else statements, not Case/Break.

    Any suggestions? I know it can be done. I have highlighted the area in question with comment tags.

    Be warned, it's a lot of code :D

    PHP:
    <?php oB_start();
    require(
    "config.php");?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Forums</title>
    <style type="text/css">
    ..my css here
    </style>
    </head>

    <body>
    <?php

    if(!$_GET[id]) //there is no forum id so show all forums... 
    ?>
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="7%" align="center" bgcolor="#E6E6E6"><strong>Forum ID </strong></td>
    <td width="33%" align="center" bgcolor="#E6E6E6"><strong>Site Forums</strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Last Post </strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Topics</strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Posts</strong></td>
    </tr>
    <?
    $forums = mysql_query("select * from forums");
    while($rows=(mysql_fetch_array($forums))) {

    ?>
    <tr>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><a href="forums.php?id=<? echo $rows['id']; ?>"><? echo $rows['name']; ?></a><BR>  <? echo $rows['description']; ?></td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>

    <?php
    }
    ?>
    <tr>
    <td height="10" colspan="5" align="right" bgcolor="#E6E6E6">&nbsp;</td>
    </tr>
    </table>

    <?
    } else if($_GET[id]) //id is present, so display forum $id and all threads within 
    {
    ?>
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="7%" align="center" bgcolor="#E6E6E6"><strong>Forum ID </strong></td>
    <td width="33%" align="center" bgcolor="#E6E6E6"><strong>Site Forums</strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Last Post </strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Topics</strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Posts</strong></td>
    </tr>
    <? 

    $threads = mysql_query("select * from threads where forumid = $id");
    while($r=(mysql_fetch_array($threads))) {

    ?>
    <tr>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><? echo $r['threadid']; ?></td>
    <td bgcolor="#FFFFFF"><a href="forums.php?id=<? echo $id; ?>&thread=<? echo $r['threadid']; ?>"><? echo $r['title']; ?></a><BR>  <? echo $r['user']; ?>
    <? //this above creates a link to the thread..forum?id=$id&thread=$threadid ?></td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>

    <?
    }
    ?>
    <tr>
    <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="createtopic.php"><strong>Create New Topic</strong> </a></td>
    </tr>
    </table>
    <?
    }
    ?>
    <?
    /*
    ##############################
    This is the problem code. I need to get the thread ID from the url, so as I can select the appropriate thread from the database. However, whilst the link displays properly, the page does not refresh and show the thread and the message..
    ##############################
    */
    } else if($_GET[thread]) {
    ?>
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="7%" align="center" bgcolor="#E6E6E6"><strong>Forum ID </strong></td>
    <td align="center" bgcolor="#E6E6E6"><strong>Thread</strong></td>
    </tr>
    <? 

    $threads = mysql_query("select * from threads where threadid = $thread");
    while($r=(mysql_fetch_array($threads))) {

    ?>
    <tr>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><? echo $r['threadid']; ?></td>
    <td bgcolor="#FFFFFF"><a href="forums.php?id=<? echo $id; ?>&thread=<? echo $r['threadid']; ?>"><? echo $r['title']; ?></a><BR>  <? echo $r['post']; ?></td>
    </tr>

    <?
    }
    ?>
    <tr>
    <td colspan="2" align="right" bgcolor="#E6E6E6"><a href="createtopic.php"><strong>Add reply</strong> </a></td>
    </tr>
    </table>
    <?
    }
    ?>
    </body>
    </html>

    Thanks.
     
  2. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    Nevermind...heh SitePoint helped me figure it out ;).

    just had to redesign the if/else statement a tad and get the variables before hand rather than as I asked for them
     
  3. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    hehe SPF are great for coding help. I was checking out your site just before you posted, everything was working :)
     
  4. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    I'm currently redoing the CMS Code...to further extend my knowledge and try things better, and I figured custom forums would be a great thing to design.

    They are working pretty well, I'm yet to deal with the admin side of it but as for general structure and appearance its looking quite nice :)

    Gotta get an avatar system working now..heh.
     
  5. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    Cool, I would also highly suggest you look into security is well, like when users submit stuff or when you get the forum details using its ID, adding security checks to make sure they are numbers and nothing else.
     
  6. Nic

    Nic Sleepy Head

    Likes Received:
    17
    Trophy Points:
    38
    You know your a genious already waffles :D
     
  7. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    I hate bumping older threads...heh but.. :) I've finished recoding my custom forums.

    Every line custom coded ableit a little help with my redirection page from the geniuses over @ sitepoint.

    http://www.wafflesweb.co.uk/forums/forum.php


    try and break them..actually don't. I'm still tweaking it and they don't look all that pretty, but they are fully functional.

    Also forgive that every post is by "Waffles", merely for testing purposes as I will soon be coding my own user system, hopefully.

    I have some work to do with checking for valid IDs etc...but it's workin ;)

    To do list
    ~ User system so logged in post with their username - 30% complete
    ~ BB Code and Admin/Mod CP - 0%
    ~ Edit posts - 90%
    ~ Avatar System - 60% complete
     
  8. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    good work Waffle! keep us updated, would love to see how you progress.
     
  9. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    Updates
    Admin CP - Add New Forum, Edit Forum functions added.

    --------------

    One thing that I'm at a lost to is categories.

    What code would you use to display forums in their own section...

    add a field called category, assign them like "General Talk", "Web Development" etc..then have a script that echoes out forums in separate categories..

    General Discussion
    ~ Testing
    ~ Sports

    Web Development
    ~ PHP
    ~ HTML

    etc?

    Would you need a loop within a loop..

    PHP:
    $sql "SELECT * FROM forums";
    $sql mysql_query($sql);
    while(
    $f=(mysql_fetch_array($sql) {

    $id $f['id'];
    //etc
    $cat $f['category'];

    //then what?

    /*presuming category was stored as a string as opposed to an integer...

    int would be easy as you could just increment the value of category 

    and then echo out a new forum block for each one..

    but string would not work so easily, 

    unless category/category id?*/
    ?>
     
  10. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    yes a loop within a loop, the only down side is, the more categories there are the more queries there will be.

    there are other solutions, like using arrays but they are more difficult to work with and for me to understand.
     

Share This Page