SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My custom coded forums...little help

    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.


    I'd rather not post my source code but I will if necessary. I have supplied code but with the acutal display part removed, so hopefully it will be enough to get my point across.
    PHP Code:
    <?php 
    require("config.php");?>

    <?php

    if(!$_GET[id]) //there is no forum id so show all forums... 
    ?>

    [ begin content box ]
    <?
    $forums 
    mysql_query("select * from forums");
    while(
    $rows=(mysql_fetch_array($forums))) {
    ?>

    [loop all the forums names, descriptions and a link like: forums.php?id=$forumid

    <?php
    }
    ?>

    [ end content box]

    <?
    } else if($_GET[id]) //id is present, so display forum $id and all threads within 
    {
    ?>

    [start of chosen forums content box]
    <? 

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

    ?>

    [show all threads currently in the chosen forum, make links out of thread like:

    forums.php?id=$forumid&thread=$threadid

    <?
    }
    ?>

    [close forums content box]
    <?
    }
    ?>
    <?
    /*
    ##############################
    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]) {
    ?>
    [show top of thread content box]
    <? 

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

    ?>

    [show the thread and any replies for the thread]
    <?
    }
    ?>

    [close the thread and reply content box]

    <?
    }
    ?>
    Thanks.

    Appreciate this may be hard to understand, but thanks for any help.

  2. #2
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:

    PHP Code:
    else if($_GET[id] && $_GET[thread]) 
    that 'll do
    The Path of excess leeds to the tower of wisdom (W. Blake)

  3. #3
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had initially tried that, but nothing happens unfortunately.

    If I change it to :

    PHP Code:
     if($_GET[id] && $_GET[thread]) 
    It does work, except it displays all the threads, and the posts to the chosen thread, rather than just the chosen threads posts..if that makes sense.

    I'm testing offline and can't upload it, as of yet to show what happens.


    also I tried the code you supplied, and then echoed $thread, and nothing is returned. This to me means that the variable $thread isn't being set when the link is chosen. Yet if just an if is used, the variable is assigned.

  4. #4
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok then the hard way:

    I did the same thing once with a photoalbum with different subjects, if a subject is clicked you get the thumbnails, if you click the thumbnail you get the picture in full size. basically the same thing.
    This is what I did to achieve it (I allready renamed vars to make it more understandable):

    PHP Code:
    //put this somewhere at the beginning of your page
     
    $fid = (int)($_GET['fid']); //forum ID
     
    $tid = (int)($_GET['tid']); //Thread ID
     
    $aid = (int)($_GET['aid']); //ArticleID

    //page is loaded the first time so you have no vars
    if(empty($fid) && empty($tid) && empty($aid))
    {
      echo 
    all the forums with their links
    }
    //a forum is selected
    elseif($fid && empty($tid) && empty($aid))
    {
     echo 
    all the threads for $fid
    }
    //a Thread is selected
    elseif($fid && $tid && empty($aid))
    {
     echo 
    all the posts for this threads (
    }
    //a post is selected
    elseif($aid)
    {
     echo 
    the post

    hope this helps
    The Path of excess leeds to the tower of wisdom (W. Blake)

  5. #5
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    id is always true so it always shows the forum because that is your first test.

    Isnt that the case?
    isempty()

  6. #6
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paulyG
    id is always true so it always shows the forum because that is your first test.

    Isnt that the case?
    in my code?
    The Path of excess leeds to the tower of wisdom (W. Blake)

  7. #7
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT:

    All working perfectly, thank you very much!

  8. #8
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your welcome
    The Path of excess leeds to the tower of wisdom (W. Blake)


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
  •