我需要一个表格来记录用户在 WordPress 中所做的某些操作。
到目前为止,这是我已经准备好的数据库模式:
id bigint(20) NOT NULL AUTO_INCREMENT,
uid bigint(20) NOT NULL,
type VARCHAR(256) NOT NULL,
data1 TEXT NOT NULL,
data2 TEXT NOT NULL,
data3 TEXT NOT NULL,
timestamp bigint(20) NOT NULL,
UNIQUE KEY id (id)
让我澄清一下:
uid: User ID of the wordpress user
type: Type of action the user made (can be 'comment', 'new_post', 'login', etc)
data1/2/3: additional data (for example, ID of comment or post made)
要显示日志,我会查询数据库并运行某个过滤器以获取要为该特定日志显示的文本。所以它的工作原理是这样的:
if( $type == 'comment') {
$comment = get_comment( $data1 );
$user = get_user($uid);
echo "User {$user->name} has made a <a href='{$comment->permalink}'>comment</a>";
}
这是最有效的做事方式吗?这对我来说似乎很好,因为我不想只将 HTML 存储在要输出的日志表中。
但是,问题出现在我想在满足某些条件时隐藏特定日志条目的地方。例如,如果评论不再存在,我想隐藏该条目。这会给分页带来一些问题。关于如何克服这个问题的任何建议?
谢谢!
编辑:
myplugin_transactions
id bigint(20) NOT NULL AUTO_INCREMENT,
user_id bigint(20) NOT NULL,
type VARCHAR(256) NOT NULL,
timestamp bigint(20) NOT NULL,
UNIQUE KEY id (id)
myplugin_meta
id bigint(20) NOT NULL AUTO_INCREMENT,
txn_id bigint(20) NOT NULL,
key VARCHAR(256) NOT NULL,
data TEXT NOT NULL,
UNIQUE KEY id (id)
Lets say I want to select * from myplugin_transactions where data1 would usually have had been 'x' and data2 been 'y'. How should I do it in this case?
SELECT * FROM myplugin_transactions LEFT JOIN myplugin_meta ON myplugin_transactions.id = myplugin_meta.txn_id WHERE ( ... ? )