Jump to content

Looking for some help


stelthius

Recommended Posts

Evening everyone,

 

I'm currently working on a basic forum system and im requiring some help i know ive done this wrong so im looking here for some advice on correcting this... the forum is nothing major its just for users to use on the site plus its a new challenge for my, my main problem is my table layout its no were near as efficiant as it could be and its giving me a head ache trying to get post and topic details from it, post count, topic count etc...

 

im going to post up my MySQL table in hope someone can give me some help on putting it together better...

 

mysqltablesforum.jpg

 

And here is the main forum display code im using and im trying to get topics & posts to display in, code isnt clean, table is messy and there is no layout to it its bare...

 

echo "<table border='1' width='100%'>";

$threads = mysql_query("SELECT * FROM `forum_thread` WHERE thr_id = '1'");
$threads = mysql_num_rows($threads);

$posts = mysql_query("SELECT * FROM `forum_posts` WHERE thr_id = '1'");
$posts = mysql_num_rows($posts);

$fetch1 = mysql_query("SELECT * FROM `forum_category`");
while ($category = mysql_fetch_array($fetch1))
    {
        
        echo "<tr>
            <td>".$category[name]."</td>
               </tr>
              <tr>
             <td>
               <table border='1' width='100%'>";
                       
        $fetch2 = mysql_query("SELECT * FROM `forum_topic` WHERE `cat_id` = '$category[id]'");
        while ($topic = mysql_fetch_array($fetch2))
            {

                echo "
                      <tr>
                    <td><a href='?page=forum&id=$topic[id]'>".$topic[name]."</a><br><i>".$topic[description]."</i></td>
                    <td width='121' align='center'>".$threads."</td>
                    <td width='142' align='center'>".$posts."</td>
                    </tr>";
                    
            }
        echo "</table>";
    }
echo "</tr></td></table>";

$rows = mysql_num_rows($fetch1);
if ($rows == 0)
{
echo ("<center><b>Forum is Empty<b></center>");
}

 

Any help is greatly appretiated..

 

i forgot to mention i used thr_id='1' for now just to get the table fixed up so do some testing on it.. im actually struggling on a way to get the category ID and then get the amount of topics / posts within that category and displaying it as the categorie's will be added via a admincp so it needs to update these on its own without me having to keep adding queries in there, if that makes sense at all sorry if it doesnt..

Link to comment
Share on other sites

Add a

or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR);  

to your queries, so it would be like:

$threads = mysql_query("SELECT * FROM `forum_thread` WHERE thr_id = '1'") or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR);

Post up if any errors show.

Link to comment
Share on other sites

Hello,

 

I think i asked my actual question the wrong way round, my problem is getting it to display the amount of posts & threads inside a category, without having to call the thread_id, so basicly my code needs to see what categories are on the page, then get the cat_id's then see what threads are inside that cat & what posts are inside that cat and display them on the main page... i really dont know how to explain it in a way that would make the most sense im sorry..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.