custom coded forums, in development...

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 :smiley:

[PHP]

<?php oB_start(); require("config.php");?> Forums ..my css here <?php

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

<? $forums = mysql_query("select * from forums"); while($rows=(mysql_fetch_array($forums))) {

?>

<?php } ?>
Forum ID Site Forums Last Post Topics Posts
<? echo $rows['id']; ?> <? echo $rows['name']; ?>
<? echo $rows['description']; ?>
     
 
<? } else if($_GET[id]) //id is present, so display forum $id and all threads within { ?> <?

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

?>

<? } ?>
Forum ID Site Forums Last Post Topics Posts
<? echo $r['threadid']; ?> <? echo $r['title']; ?>
<? echo $r['user']; ?> <? //this above creates a link to the thread..forum?id=$id&thread=$threadid ?>
     
Create New Topic
<? } ?> <? /* ############################## 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]) { ?> <?

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

?>

<? } ?>
Forum ID Thread
<? echo $r['threadid']; ?> <? echo $r['title']; ?>
<? echo $r['post']; ?>
Add reply
<? } ?> [/PHP]

Thanks.

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

hehe SPF are great for coding help. I was checking out your site just before you posted, everything was working :slight_smile:

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 :slight_smile:

Gotta get an avatar system working now..heh.

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.

[QUOTE=Waffle]
to further extend my knowledge

[/QUOTE]

You know your a genious already waffles :smiley:

I hate bumping older threads…heh but.. :slight_smile: 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 :wink:

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

good work Waffle! keep us updated, would love to see how you progress.

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?*/
?>
[/PHP]

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.