Hello;
I have my own custom user forum that I made, and am working to update and modify the way it works. I have it split up into 6 distinct forums, with each forum having an unlimited number of threads to create, and any time a post is made to a thread, it gets noted as to which thread it belongs to, and which forum as well. The posting part and the display part work just wonderfully. However, I need to learn, and not need to get told to 'just go get a canned script', as I am learning how to program php myself, but I need to find out the best way, using the current display script I wrote, how to display how many posts are in each thread. Here is the current display code for the thread display:
This is the header and setup info:
<?php
session_start();
if ($_SESSION['Valid'] <> true) {
$USID="Visitor";
}
include "db_config.php";
mysql_select_db(iceregen_MStudio);
echo '<body bgcolor="#000000">';
$Forum2Display=$_GET['forum'];
$_SESSION['forum']=$Forum2Display;
$a=1;
echo '<table border="2" style="border: 2 solid #800000; padding: 1" width="100%" bgcolor="#CCCCCC">';
echo ' <tr>';
echo ' <td width="100%"><font face="Arial" color="#000000">Forum is : <font face="Arial" color="#FF0000">' . $_SESSION['forum'] . ' </td>';
echo ' </tr>';
echo '</table><br>'
;
This is the query and display portion:
$query = "SELECT ThreadID, forum, thread, origthread FROM forums";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if ($row['forum'] == $_SESSION['forum'] AND $row['origthread'] == 'yes')
{
$a=$a+1;
$passthread = urlencode($row['thread']);
echo '<table width="100%" border="2" cellspacing="2" cellpadding="2" bgcolor="#84BBD9" bordercolor="#400000">';
echo ' <tr>';
echo '<td width="20%">' . $row['thread'] . ' <a href="/forum_thread.php?passthread=' . $passthread . '" target ="_self">View</a> '. $a . '</td>';
echo ' </tr>';
echo '</table>';
}
}
mysql_close();
I was experimenting with the variable $a to see how I could utilize it to count, but thats when I got frustrated and decided to seek help.
The rest of the code is the options for the user to choose from after the forum thread list is displayed:
if ($_SESSION['Valid'] == true) {
echo '<a href="/thread_new.php" target="_self">Post New Thread</a> ';
}
echo '<a href="/forum_select.php" target="_self">Back to Forums</a> ';
?>
Now, the need I have, is, how do I best count up how many posts belong to each thread? My forum table is set up like this:
ThreadID --- AutoIncrement <----thread identifier
forum ------- varchar(50) <---forum thread belongs to
thread ------ varchar(200) <---thread title
origthread - char(3) <---Yes or No if it is an original thread
message --- text <---text of thread message
user --------- varchar(30) <---user who posted thread message
date --------- date <---date thread was posted
What I need to do, is somehow include in my current php code, a way to count up how many messages are in each original thread in the currently displayed forum. I would appreciate any help with how I can accomplish this please.
Thank you;
Ice