PHP
  Home arrow PHP arrow Page 2 - Creating an Administration Area for a ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Creating an Administration Area for a Simple Threaded Discussion Forum
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-10-23

    Table of Contents:
  • Creating an Administration Area for a Simple Threaded Discussion Forum
  • Code
  • The delall() and deltopic($uid) functions
  • Database connection, bad words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating an Administration Area for a Simple Threaded Discussion Forum - Code


    (Page 2 of 4 )

    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


       · This is a very good article, clearly and profesionally written by this wonderful and...
       · Thanks for the encouraging comments!
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT