...

View Full Version : Adding Thread help (Forum)



NightFlyer
05-16-2008, 08:13 PM
I'm making a forum from scratch.

I have made the boards which is also the category and if the board ID is 7 it will go to the thread that is ID 7 but I don't want that. I want it where when you click a board it goes and views the threads.

Viewthread.php

<?php require_once("config.php");
$id = $_GET['id'];
$name = $_GET['name'];
$result = mysql_query("SELECT * FROM threads WHERE `id`='$id'") or die(mysql_error());

echo " <table border='1' 'width = 30&#37;' > ";

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<hr>";
echo "<b>Username:</b> "; echo ''.$row['name'];
echo "<hr>";
}
?>

Addthread.php

<?php include("config.php");
$name = $_POST['name'];

mysql_query("INSERT INTO threads
(name) VALUES('$name' ) ")
or die(mysql_error()); ?>

Please help thanks :)

NightFlyer
05-16-2008, 10:34 PM
Anyone?

aedrin
05-16-2008, 10:36 PM
Your question is confusing. You need to abstract it more.

NightFlyer
05-17-2008, 12:17 AM
READ IT aGaIn i eDiTEd iT.>.>.>

Fou-Lu
05-17-2008, 01:05 AM
No need to shout mate.
Well, I'm with aedrin on this one for sure. The code you have posted is to display a specific thread and how to add a new thread. I don't see anything that refers to the actual board itself. So I'm not sure what you are looking for either. Fetching all the threads info isn't a good idea if you want to display it on a 'board' type listing, like we have here, so you would select say the thread title, maybe the thread author and dates, and of course the thread id. Do this all on a where clause for the board you are looking for, and you should get a list of all the threads associated with that category and you can loop through them. This of course assumes that you are referring to a specific board/category within each of your threads - otherwise you need to specify your database schema so we can see if there is away around it.

NightFlyer
05-17-2008, 02:38 AM
Oh I see. Thanks :D
PS. I was axednetly on caps lock :/

Fou-Lu
05-17-2008, 03:01 AM
Thats ok mate, no worries.
Is this what you are looking to do though, does it answer what you are looking for?

NightFlyer
05-17-2008, 03:54 AM
Kinda. Now all I need is help with replying to a thread. Here is what I have.

addreply.php

<?php require_once("config.php");
$id =$_POST['id'];

$username=$_POST['username'];
$message=$_POST['message'];

mysql_query("INSERT INTO boards(rusername,rmessage)Values('$rusername','$rmessage')") or die(mysql_error());
?>

viewthread.php

<?php require_once("config.php");
$id = $_GET['id'];
$name = $_GET['name'];
$rusername =$_GET['rusername'];
$rmessage=$_GET['rmessage'];
$result = mysql_query("SELECT * FROM boards WHERE `id`='$id'") or die(mysql_error());
echo " <table border='1' 'width = 30&#37;' > ";

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<hr>";
echo "<b>Username:</b> "; echo ''.$row['message'];
echo "<hr>";
echo '<a href="/forum/replybox.php?id=' . $row['id'] . '">Go view replies</a>';
}
?>

See my problem is, There is no select from threads and I cannot have two querys in there on the same page.

So I don't know what to do :(

Fou-Lu
05-17-2008, 06:00 AM
Without your database schema I cannot really help you all that much.
But, I can tell you you can have as many queries as you want on a page (limited by the memory of course, but that will take awhile ;)), and don't forget you can join your SQL queryies if you need to.
For example, using a join (not sure if it relates to your tables or not, but its just an example):


SELECT t.*, c.categoryName FROM `thread` t INNER JOIN `category` c ON (t.catID = c.catID) WHERE t.tID = 5

That would get all the information about thread with the ID of 5, and the category name associated with that threads category ID.

Search the net for 'SQL Join', if you need more examples, there are many different joins available, and they are extremely helpful :)

NightFlyer
05-17-2008, 07:23 AM
Thanks but I don't think I need that.

When you click a board in here it'll show threads from the board. In my case it will only show one thread. It keeps making IDs of threads and not putting the ids in the id of the board so it's all spreded out.

In that case it has something to do with:

addtopic.php


<?php include("config.php");
$id = $_GET['id'];
$id =$_POST['id'];
$username = $_POST['username'];
$message =$_POST['message'];

mysql_query("INSERT INTO threads
(username,message) VALUES('$username','$message' ) ")
or die(mysql_error()); ?>

Or/And

createtopic.php


<?php include("config.php");
$id = $_GET['id']; ?><table width="897" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="261" height="29" valign="top"><form name="form1" method="post" action="addthread.php">
<label>
<input type="text" name="name" id="message">
</label>
</form> </td>
<td width="636">&nbsp;</td>
</tr>
<tr>
<td height="185">&nbsp;</td>
<td>&nbsp;</td>
</tr>


</table>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum