<?
include("config.php");
$category = $_GET['category'];
$newthread = $_GET['newthread'];
session_start();
$author = $_SESSION['username'];
// DISPLAY THREADS
if (isset($_GET['category'])) {
$result = mysql_query("SELECT * FROM categories WHERE id='$category'")
or die("SELECT Error1: " .mysql_error());
$num=mysql_numrows($result);
while ($row = mysql_fetch_array($result))
{
$title = $row['title'];
}
$pagetitle = "$title threads";
include("head.php");
echo "<h1>$title forum</h1>
<table width='100%' border='0'>
<tr><td align='left'><p><a href='forum.php'>< Back to categories</a></p></td>
<td align='right'><p><a href='forumhandle.php?newthread=true&category=$category'>Start new thread</a></p></td></tr></table>";
echo "<table width='100%' border='0' cellspacing=0 cellpadding=2>
<tr class='threadhead'>
<td width='40%'>Thread</td>
<td width='25%'>Thread Started</td>
<td width='25%'>Last Post</td>
<td width='10%'>Posts</td>
</tr>";
// END OF HEADINGS
$result = mysql_query("SELECT * FROM forum_threads WHERE category='$category' ORDER BY id DESC")
or die("SELECT Error1: " .mysql_error());
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
if ($i % 2) {
$bgcolor = "threadtable";
}
else {
$bgcolor = "threadtable2";
}
$id=mysql_result($result,$i,"id");
$title=mysql_result($result,$i,"title");
$author=mysql_result($result,$i,"author");
$category=mysql_result($result,$i,"category");
$startdate=mysql_result($result,$i,"startdate");
$starttime=mysql_result($result,$i,"starttime");
$query = mysql_query( "SELECT * FROM forum WHERE threadid='$id' AND category='$category'" ) or die("SELECT Error2: " .mysql_error());
$numero=mysql_numrows($query);
$query = mysql_query( "SELECT id FROM users WHERE username='$author'" ) or die("SELECT Error3: " .mysql_error());
$authorid=mysql_result($query,0,"id");
$query = mysql_query( "SELECT * FROM forum WHERE threadid='$id' AND category='$category' ORDER BY 'datetime' ASC LIMIT 1" ) or die("SELECT Error4: " .mysql_error());
$num1=mysql_numrows($query);
$i=0;
while ($i < $num1) {
$author=mysql_result($query,$i,"author");
$time=mysql_result($query,$i,"time");
$date=mysql_result($query,$i,"date");
$today = date("d/m/y");
if ($date == $today) {$date = "Today"; }
{$date = "Today";}
$i++;
}
echo "
<tr class='$bgcolor'>
<td valign='top'><a href='showthread.php?category=$category&thread=$id'>$title</a></td>
<td valign='top'>$startdate at $starttime <br />by <a href='viewprofile?profile_id=$authorid'>$author</a></td>
<td valign='top'>$date at $time</td>
<td valign='top'>$numero</td>
</tr>";
$i++;
}
echo "</table>";
include("foot.php");
}
// END DISPLAY THREADS
?>