12-05-2000, 10:39 PM
Well, here's a little script I wrote to update the post count stored in the user table with the actual number of
posts that user has made. When would you want to run something like this? Well, normally you should
never have to, but in case your user's post counts become inaccurate, you can reset them with this.
The main reason I wrote this, however, was to update a user's post count excluding certain fourms, for
example if you have a testing forum and don't want those posts included in the user's total. If you would
like to do something like this, just look at the comments in the script and make the changes needed.
Just name upload this code to admin/usercounts.php
Enjoy!
<?php
if (function_exists("set_time_limit")==1 and get_cfg_var("safe_mode")==0) {
set_time_limit(1200);
}
require ("global.php");
?>
<html>
<head>
<STYLE type=text/css>
BODY {
font-family: arial;
font-size: 10pt;
font-variant: normal;
font-style: normal;
}
P {
font-family: arial;
font-size: 10pt;
font-variant: normal;
font-style: normal;
}
</STYLE>
</head>
<body>
<?php
// ###################### Start user choices #######################
if (isset($action)==0 or $action=="") {
echo "<p><b>Update User Counts</b> - updates user post counts, excluding certain forums<br>\n";
echo doformheader("usercounts","updateuser");
echo "<table border=0>";
echo makeinputcode("Number of users to do per cycle","perpage","500");
echo doformfooter();
}
// ###################### Start update user #######################
if ($action=="updateuser") {
if (isset($perpage)==0 or $perpage=="") {
$perpage=500;
}
if (isset($startat)==0 or $startat=="") {
$startat=0;
}
$finishat=$startat+$perpage;
echo "<p>User ids:</p>";
$users=$DB_site->query("SELECT userid,username,posts FROM user WHERE userid>=$startat AND userid<$finishat ORDER BY userid DESC");
while ($user=$DB_site->fetch_array($users)) {
$userid=$user[userid];
// update user stuff
// If you want to exclude a certain forum, just add it to the query below
// Ex.: AND thread.forumid<>1
if ($posts=$DB_site->query_first("SELECT COUNT(post.postid) AS numberposts FROM post,thread WHERE thread.threadid=post.threadid AND post.userid=$userid")) {
$numposts=$posts[numberposts];
} else {
$numposts=0;
}
$DB_site->query("UPDATE user SET user.posts=$numposts WHERE userid=$user[userid]");
echo "$user[userid] $user[username] $numposts <br>\n";
flush();
}
if ($checkmore=$DB_site->query_first("SELECT userid FROM user WHERE userid>=$finishat")) {
echo "<script language=\"javascript\">window.location=\"usercounts.php?action=updateuser&startat=$finishat&perpage=$perpage\";</script>";
echo "<p><a href=\"usercounts.php?action=updateuser&startat=$finishat&perpage=$perpage\">Click here to continue updating users</a></p>";
} else {
echo "<p>All done!</p>";
}
}
?>
</body>
</html>
posts that user has made. When would you want to run something like this? Well, normally you should
never have to, but in case your user's post counts become inaccurate, you can reset them with this.
The main reason I wrote this, however, was to update a user's post count excluding certain fourms, for
example if you have a testing forum and don't want those posts included in the user's total. If you would
like to do something like this, just look at the comments in the script and make the changes needed.
Just name upload this code to admin/usercounts.php
Enjoy!
<?php
if (function_exists("set_time_limit")==1 and get_cfg_var("safe_mode")==0) {
set_time_limit(1200);
}
require ("global.php");
?>
<html>
<head>
<STYLE type=text/css>
BODY {
font-family: arial;
font-size: 10pt;
font-variant: normal;
font-style: normal;
}
P {
font-family: arial;
font-size: 10pt;
font-variant: normal;
font-style: normal;
}
</STYLE>
</head>
<body>
<?php
// ###################### Start user choices #######################
if (isset($action)==0 or $action=="") {
echo "<p><b>Update User Counts</b> - updates user post counts, excluding certain forums<br>\n";
echo doformheader("usercounts","updateuser");
echo "<table border=0>";
echo makeinputcode("Number of users to do per cycle","perpage","500");
echo doformfooter();
}
// ###################### Start update user #######################
if ($action=="updateuser") {
if (isset($perpage)==0 or $perpage=="") {
$perpage=500;
}
if (isset($startat)==0 or $startat=="") {
$startat=0;
}
$finishat=$startat+$perpage;
echo "<p>User ids:</p>";
$users=$DB_site->query("SELECT userid,username,posts FROM user WHERE userid>=$startat AND userid<$finishat ORDER BY userid DESC");
while ($user=$DB_site->fetch_array($users)) {
$userid=$user[userid];
// update user stuff
// If you want to exclude a certain forum, just add it to the query below
// Ex.: AND thread.forumid<>1
if ($posts=$DB_site->query_first("SELECT COUNT(post.postid) AS numberposts FROM post,thread WHERE thread.threadid=post.threadid AND post.userid=$userid")) {
$numposts=$posts[numberposts];
} else {
$numposts=0;
}
$DB_site->query("UPDATE user SET user.posts=$numposts WHERE userid=$user[userid]");
echo "$user[userid] $user[username] $numposts <br>\n";
flush();
}
if ($checkmore=$DB_site->query_first("SELECT userid FROM user WHERE userid>=$finishat")) {
echo "<script language=\"javascript\">window.location=\"usercounts.php?action=updateuser&startat=$finishat&perpage=$perpage\";</script>";
echo "<p><a href=\"usercounts.php?action=updateuser&startat=$finishat&perpage=$perpage\">Click here to continue updating users</a></p>";
} else {
echo "<p>All done!</p>";
}
}
?>
</body>
</html>