Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
Add a column to your classified table in your database called 'authorized', make it datatype 'tinyint' with a default value of 0.
Hopefully you've incorporated some form of administration login so that your pages can recognize you as being logged on. If this is the case follow the generic steps below;
1. Instantiate a var for authorized users being logged in.
e.g.
2. Do a test to check if your logged.
e.g.
PHP Code:
if(isset($_SESSION['access']) && $_SESSION['access'] == 'admin'){
$auth = 1;
}
3. Apply some self administration to the classifieds which display on the page. If $auth == 0, only authorised classifieds display. If $auth == 1, all classifieds display with the inclusion of a radio group in each record carrying the checked values '1' for approved and '0' for declined. Each form instance includes a hidden form value that carries the recordID for your table row.
e.g.
PHP Code:
<?php
if($auth == 1){
$sql = "SELECT * FROM table_name";
}else{
$sql = "SELECT * FROM table_name WHERE authorized = 1";
}
$rsClassifieds = mysql_query($sql) or die(mysql_error());
$row_rsClassifieds = mysql_fetch_assoc($rsClassifieds);
// start record display
if($auth == 1){
?>
<form name="approval" method="POST">
<input type="hidden" name="recordID" value="<?php echo $recordID; ?>" />
<label><input type="radio" name="approve" value="1" />
Approve :: </label>
<label><input type="radio" name="approve" value="0" />
<input name="Submit" type="submit" value="Submit" />
Decline</label>
<input name="doRecord" type="hidden" value="ok" />
<input name="Submit" type="submit" value="Submit" />
</form>
<?php
// end if conditional for displaying admin form
}
// end record display ?>
4. Code in your record management at the top of the page.
i.e.
PHP Code:
if(isset($_POST['doRecord']) && $_POST['doRecord'] == 'ok'){
$recordID = 0;
if($_POST['approve'] == 1){
$sql = "UPDATE table_name SET authorized = 1 WHERE recordID = ".$recordID;
$query = mysql_query($sql) or die(mysql_error());
}
if($_POST['approve'] == 0){
$recordID = $_POST['recordID'];
$sql = "DELETE FROM table_name WHERE recordID = ".$recordID;
$query = mysql_query($sql) or die(mysql_error());
}
// end if form submitted condition
}
That shoud give an idea of one approach.
|