how to lock a topic in a forum?
Moderator: General Moderators
Re: how to lock a topic in a forum?
SELECT the sticky column, ORDER BY sticky DESC. As you're iterating over the returned rows, if $row['sticky'] == 1, then label it as sticky.
-
beginner123
- Forum Commoner
- Posts: 70
- Joined: Fri Feb 24, 2012 9:56 am
Re: how to lock a topic in a forum?
oh I think I understand now. So I'm just putting all the topics in order so if one topic has sticky = 1 then it will always stay at the top?
but what about locking the forum to stop people posting in it?
but what about locking the forum to stop people posting in it?
Re: how to lock a topic in a forum?
You'd use basically the same logic for displaying whether a topic is locked or not. In the thread view, just remove the reply button if locked = 1
-
beginner123
- Forum Commoner
- Posts: 70
- Joined: Fri Feb 24, 2012 9:56 am
Re: how to lock a topic in a forum?
thanks for all the help. sorry it took so long to explain 
-
beginner123
- Forum Commoner
- Posts: 70
- Joined: Fri Feb 24, 2012 9:56 am
Re: how to lock a topic in a forum?
I changed the value of sticky in a category to 1 but when I put in ORDER BY sticky DESC I just get errrors
heres the home page where I want to put the code:
if i add the code it skips to
and doesn't display the categories
heres the home page where I want to put the code:
Code: Select all
<?php
//index.php
include 'connect.php';
include 'header.php';
$sql = "SELECT
categories.categoryID,
categories.categoryName,
categories.categoryDescription,
COUNT(topics.topicID) AS topics
FROM
categories
//I tried putting ORDER BY sticky here
LEFT JOIN
topics
ON
topics.topicID = categories.categoryID
GROUP BY
categories.categoryName, categories.categoryDescription, categories.categoryID";
$result = mysql_query($sql);
if(!$result)
{
echo 'The categories could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
//no categories have been made yet
echo 'No categories defined yet.';
}
else
{
//make the table
echo '<table border="1">
<tr>
<th>Category</th>
<th>Last topic</th>
</tr>';
while($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo '<td class="leftpart">';
echo '<h3><a href="category.php?id=' . $row['categoryID'] . '">' . $row['categoryName'] . '</a></h3>' . $row['categoryDescription'];
echo '</td>';
echo '<td class="rightpart">';
//fetch last topic for each category
$topicsql = "SELECT
topicID,
topicSubject,
topicDate,
topicCategory
FROM
topics
WHERE
topicCategory = " . $row['categoryID'] . "
ORDER BY
topicDate
DESC
LIMIT
1";
$topicsresult = mysql_query($topicsql);
if(!$topicsresult)
{
//error
echo 'Last topic could not be displayed.';
}
else
{
if(mysql_num_rows($topicsresult) == 0)
{
echo 'no topics';
}
else
{
while($topicrow = mysql_fetch_assoc($topicsresult))
echo '<a href="topic.php?id=' . $topicrow['topicID'] . '">' . $topicrow['topicSubject'] . '</a> at ' . date('d-m-Y', strtotime($topicrow['topicDate']));
}
}
echo '</td>';
echo '</tr>';
}
}
}
include 'footer.php';
?>
Code: Select all
if(!$result)
{
echo 'The categories could not be displayed, please try again later.';
}
Re: how to lock a topic in a forum?
ORDER BY must come after GROUP BY
-
beginner123
- Forum Commoner
- Posts: 70
- Joined: Fri Feb 24, 2012 9:56 am