jd57
Založený: 07.04.2009
Príspevky: 2
Zaslal: 2009-04-07 20:07
Návrat hore
Odpovedať s citátom
|
Hi Everyone,
I would like to add a code for a text field that allows me to write a message why an item was deleted from mysql database.
Hope you can help JD
|
doug
Založený: 10.02.2003
Príspevky: 1013
Bydlisko: Denver, Colorado (USA)
Zaslal: 2009-04-08 13:06
Návrat hore
Odpovedať s citátom
|
Deleting records is considered by many users to be a bad idea. Sometimes it is better to add a field named deleted (which has a default value of 0) and use a filter to display all records except those where deleted has been set to 1 using a trigger. Comment out the field array for the `deleted` column and use a trigger.
| Kód: |
// phpMyEdit form
$opts['filters'] = 'PMEtable0.deleted = "0"';
$opts['triggers']['delete']['before'] = 'mark_as_deleted.TDB.inc';
/*
$opts['fdd']['deleted'] = array(
'css' => array('postfix' => 'right-justify'),
'default' => '0',
'input' => '',
'maxlen' => 1,
'name' => 'Deleted',
'options' => 'ACP',
'select' => 'D',
'sqlw' => 'TRIM("$val_as")',
'values2' => array('1' => 'Yes', '0' => 'No'),
'sort' => true
);
*/
|
| Kód: |
<?php
// trigger mark_as_deleted.TDB.inc
$query2 = sprintf('UPDATE %s SET `deleted` = "1" WHERE `%s` = "%s"', $this->tb, $this->key, $this->rec);
if($this->MyQuery($query2)){
// Emulate the change_log function, saving a copy of the record flagged as deleted
if($this->logtable){
$query3 = sprintf('INSERT INTO %s'
.' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
.' VALUES (NOW(), "%s", "%s", "delete", "%s", "%s", "%s", "%s", "")',
$this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
addslashes($this->rec), addslashes($key), addslashes(serialize($oldvals)));
$this->myquery($query3, __LINE__);
}
return false;
}else{
echo "\n".'<p>'.mysql_error().'</p>';
echo "\n".'<a href="javascript:history.go(-1)" onmouseover="self.status=document.referrer;return true">Go Back</a>';
exit;
}
?> |
Naposledy upravil doug dňa 2009-06-25 02:57, celkom upravené 1 krát
|
jd57
Založený: 07.04.2009
Príspevky: 2
Zaslal: 2009-04-08 14:14
Návrat hore
Odpovedať s citátom
|
I'm sorry, my knowledge of php is at the very begining.
you are showing me 2 different codes, I'm not sure in which file this code will be pasted.
can you please explain?
|
doug
Založený: 10.02.2003
Príspevky: 1013
Bydlisko: Denver, Colorado (USA)
Zaslal: 2009-04-11 16:37
Návrat hore
Odpovedať s citátom
|
When you create tables, you can add a field that you might call a System Field. For example you might add a field named `deleted` and define it as:
| Kód: |
| TINYINT(1) NOT NULL DEFAULT '0'; |
You could then use the `deleted` field with a filter in order to list only those records whose deleted status is set to zero.
| Kód: |
| $opts['filters'] = 'deleted = "0"'; |
In most situations, it is not good to delete records. Better to leave unwanted records in the database "just in case" but to filter out their display. In other words, set the deleted value to 1 instead of actually deleting the record, and set the filter to display non-deleted (0) records.
|
|
Odoslať novú tému
Odpovedať na tému
|
|