I need to alert members of a site when their post count has reached a multiple of 100. Is it possible to run a function or echo something when a value in a mysql table reaches 100, 200, 300, etc?
Table structure:
username | password | email | posts
I’m currently displaying their post count with:
$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'];
RESOLVED: I went with Marc’s suggestion of using modulo, which suited my needs.
$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!')");
}
You need a modulo
Like this
And you can check the condition every time a user do a new post