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

The delall() and deltopic($uid) functions - 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

The delall() function is pretty straightforward. It deletes all the records in the table.

function delall(){
forumdb();
$query="Delete * from test";
$result=mysql_query($query);
if(!$result){
echo 'Could not delete records because ' .mysql_error() . '';
}else{
echo 'All records have been delete';
}
}

The deltopic($uid) function takes the uid of the record and uses that ID to delete it.

function deltopic($uid){
forumdb();
if(is_numeric($uid)){
$dbname="forum";
$host="localhost";
$dbh=mysql_connect($host) or die ('I cannot connect to the
database because: ' . mysql_error());
mysql_select_db ($dbname) or die('I cannot select the database
because: ' . mysql_error());
$query="Delete from test where uid=$uid Limit 1";
$r=mysql_query($query);
if(mysql_affected_rows()==1){
echo "Record number <b>$uid</b> deleted";
}else{
echo "Could not delete record number <b>$uid</b> because
" .mysql_error() . "";
}
}
}

In this function I've played it save and added the "Limit 1" statement to the delete query. This ensures that only one record is deleted and not all of them.



 
 
>>> 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: