当他们的帖子数达到100的倍数时,我需要提醒网站的成员。当mysql表中的值达到100,200,300等时,是否可以运行函数或回显?
表格结构:
username | password | email | posts
我目前正在显示他们的帖子数:
$sql = mysql_query("SELECT `posts` FROM `user` WHERE username='$username'") or die(mysql_error());
$row = mysql_fetch_array($sql);
echo "<br /><h4>Your posts:</h4>" . " " . $row['posts'];
已解决:我选择了Marc建议使用modulo,这符合我的需求。
$sql = mysql_query("SELECT `posts` AS posts FROM `user` WHERE username='$username'") or die(mysql_error());
$row = mysql_fetch_array($sql);
$post = $row['posts'];
if($post % 100 == 0) {
mysql_query("INSERT INTO `posts` (name, message, message_raw) VALUES ('System', '$name has reached $post posts!', '$name has reached $post posts!')");
}
答案 0 :(得分:3)
您需要modulo
模数操作。返回N的余数除以M.
喜欢这个
SELECT username
FROM `user`
WHERE username='$username' AND MOD(posts,100) = 0
您可以在每次用户发布新帖子时检查条件
答案 1 :(得分:0)