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
Thanks.
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"> </td>
<td align="center" bgcolor="#FFFFFF"> </td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
}
?>
<tr>
<td height="10" colspan="5" align="right" bgcolor="#E6E6E6"> </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"> </td>
<td align="center" bgcolor="#FFFFFF"> </td>
<td align="center" bgcolor="#FFFFFF"> </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.