Page 1 of 2
how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 10:55 am
by beginner123
I'm making a forum and I noticed that lots of forums have topics that are locked and stay at the top of the list of topics. So I was wondering how to you do this?
I will post any code about my topics if you want to see it

Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:13 am
by Celauran
Their being locked and their being stickied at the top of forums are two entirely separate issues. Both can be accomplished by setting flags on the threads in question.
Code: Select all
UPDATE table_name SET sticky = 1 WHERE thread_id = foo
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:41 am
by beginner123
ok but since I am using mysql with the forum will I need to add sticky to the topics table?
and what do you mean here
and how will I lock the topic?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:42 am
by Celauran
I can't really give you anything specific as I have no idea how your tables are setup. Every post must have a thread ID, no?
Locking it would simply be setting another flag.
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:50 am
by beginner123
but what do you mean by setting a flag?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:52 am
by Celauran
In the database. Have a column in your threads table for whether or not the thread is stickied, and another for whether or not it is locked.
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:54 am
by beginner123
no I have topicID, topicSubject, topicDate, topicCategory,and topicByUser. So I will need to add two more columns for sticky and locked?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 11:55 am
by Celauran
Precisely.
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 12:00 pm
by beginner123
ok thanks I understand but what will the code be when sticky and locked are flagged?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 12:01 pm
by Celauran
Just toggle that column from 0 to 1
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 12:39 pm
by beginner123
but what code to go with that like if(sticky = 1 & locked = 1)?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 12:49 pm
by Celauran
I don't really understand what you're asking. What code to go where? To do what?
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 1:20 pm
by beginner123
I am making the forum in php so I need to write some php code to make sticky and locked work
heres my code for creating a category:
Code: Select all
<?php
//create_cat.php
include 'connect.php';
include 'header.php';
echo '<h2>Create a category</h2>';
if($_SESSION['signed_in'] == false | $_SESSION['userLevel'] != 1 )
{
echo 'Sorry, you do not have sufficient rights to access this page.';
}
else
{
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
//the form hasn't been posted yet, display it
echo '<form method="post" action="">
Category name: <input type="text" name="categoryName" /><br />
Category description:<br /> <textarea name="categoryDescription" /></textarea><br /><br />
<input type="submit" value="Add category" />
</form>';
}
else
{
$sql = "INSERT INTO categories(categoryName, categoryDescription)
VALUES('" . mysql_real_escape_string($_POST['categoryName']) . "',
'" . mysql_real_escape_string($_POST['categoryDescription']) . "')";
$result = mysql_query($sql);
if(!$result)
{
echo 'Error' . mysql_error();
}
else
{
echo 'New category succesfully added.';
}
}
}
include 'footer.php';
?>
so I will some php code to make sticky and lock to work
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 1:22 pm
by Celauran
Code: Select all
UPDATE table_name SET sticky = 1 WHERE topic_id = whatever
I don't understand where the problem is.
Re: how to lock a topic in a forum?
Posted: Fri Mar 02, 2012 1:32 pm
by beginner123
I don't understand how the forum will know what sticky means...
how does it know that sticky will make the topic stay at the top of the list if i don't write any code for it