how to lock a topic in a forum?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

how to lock a topic in a forum?

Post 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 :)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post 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
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post 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

Code: Select all

WHERE thread_id = foo?
and how will I lock the topic?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post 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.
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post by beginner123 »

but what do you mean by setting a flag?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post 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.
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post by beginner123 »

no I have topicID, topicSubject, topicDate, topicCategory,and topicByUser. So I will need to add two more columns for sticky and locked?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post by Celauran »

Precisely.
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post by beginner123 »

ok thanks I understand but what will the code be when sticky and locked are flagged?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post by Celauran »

Just toggle that column from 0 to 1
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post by beginner123 »

but what code to go with that like if(sticky = 1 & locked = 1)?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post by Celauran »

I don't really understand what you're asking. What code to go where? To do what?
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post 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
Last edited by beginner123 on Fri Mar 02, 2012 1:25 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to lock a topic in a forum?

Post by Celauran »

Code: Select all

UPDATE table_name SET sticky = 1 WHERE topic_id = whatever
I don't understand where the problem is.
beginner123
Forum Commoner
Posts: 70
Joined: Fri Feb 24, 2012 9:56 am

Re: how to lock a topic in a forum?

Post 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
Post Reply