Home arrow PHP arrow Page 2 - Creating an Administration Area for a Simple Threaded Discussion Forum

Code - PHP

Discussion forums usually need an administrator to handle various tasks that you wouldn't want just any forum user doing, such as banning other users. This article, the second of two parts, will show you how to set up an administration area for a threaded discussion forum, and some of the functions you might want an administrator to manage.

TABLE OF CONTENTS:
  1. Creating an Administration Area for a Simple Threaded Discussion Forum
  2. Code
  3. The delall() and deltopic($uid) functions
  4. Database connection, bad words
By: Jacques Noah
Rating: starstarstarstarstar / 6
October 23, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Fig. 1 The administration page.

If you look to the navigation bar on the left, you will see that there are six options available, of which we will only implement five. The User Data  option involves a tracking system that we will not discuss in this article, so I have decided to leave it out for now. I've left the top bar where it says "Administrator:" empty in case you want to implement a login system that will enable you to show an admin name there. The text that you see in the main area comes from the default section of the switch statement. This section is executed if the variable that is being checked does not have any value in it or when the value does not match any of the conditions that have been set.

The remaining links will be implemented by the following functions:

  • function delall() - Deletes all the topics in the database.
  • function getall() - Retrieves all the main topics in the database.
  • function deltopic($uid) - Deletes a specific topic.
  • function showform() - Show a form to take words that you want banned.
  • function writeword() - Processes the above form.
  • function getword() -Displays the banned words.

Let's talk about each of the functions in detail.

Fig. 2 The listing of the topics.

function getall(){
forumdb();//gets the database connection settings
echo '<table width="360" >';
echo "<tr bgcolor="#3399CC">
<td width="180"><b> Subject </b></td>
<td width="180"><b>Record number</b><br></td>";
echo '</tr>';
echo '</table>';
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("Select * from test where parent = 0 LIMIT
$from, $max_results");
//$query="Select ip,page FROM tracker order by date";
while($row = mysql_fetch_array($sql)){
    // Build your formatted results here.
    $title=$row['title'];
    $Recid= $row['uid'];
echo '<table width="360">';
echo '<tr>
<td width="180">' .$title. '</td>
<td width="180">'.$Recid.' <a href="' .$_SERVER['PHP_SELF']. '?
id=' .$Recid. '&action=deltopics">Delete</a><br></td>';
echo '</tr>';
echo '</table>';
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num
FROM test"),0);
// Figure out the total number of pages. Always round up using
ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo '<a href="'.$_SERVER['PHP_SELF'].'?
page='.$prev.'&action=gettopics"><<Previous</a>&nbsp;';
}
for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo '<a href="'.$_SERVER['PHP_SELF'].'?
page='.$i.'&action=gettopics">'.$i.'</a>&nbsp;';
    }
}
// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$next.'&action=gettopics">Next>></a>';
}
echo "</center>";
}

The point of this function is to retrieve ALL the records in the database. Naturally you would want to display only a few records at a time. To this end, the function also includes pagination code. Also, the function presents two columns to you; one contains the title of the record and the other contains an option to delete the record. Once you click on delete, the record is removed and the list is updated and displayed.



 
 
>>> More PHP Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: