
Woran kann das Liegen??
Bitte um Hilfe bin in dem Bereich phpBB2 Blutiger Anfänger.

Danke im voraus.[/b]
Code: Alles auswählen
Unsere Benutzer haben insgesamt 13 Beiträge geschrieben.
Wir haben 4 registrierte Benutzer.
Der neueste Benutzer ist hasi_mausi.
Code: Alles auswählen
<?php
/******************************************************************************
*
* File: repair_postercount.php
* -----------------------------
*
* Purpose: This script repairs the postcount of each user.
*
* Usage: Store this script into forum root and call it as batch.
* After this delete it as well, so that nobody else can
* access it!
*
* Written: 2007-03-11
*
* Copyright: (C) 2007 Ron
*
*******************************************************************************/
define('IN_PHPBB', true);
$phpbb_root_path = "./";
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'config.'.$phpEx);
$startdate = date("Ymd-His");
// ---------------------------------------------------------------------
// This function creates a table of all users.
// ---------------------------------------------------------------------
function get_usertable()
{
$tabelle = array();
$sql = "SELECT user_id, username FROM " . USERS_TABLE;
$result = mysql_query($sql);
if(!$result) {
die("***** ERROR: Cannot read user table<br>");
}
else {
$i = 0;
while ($zeile = mysql_fetch_row ($result)) {
$tabelle [$i]['id'] = $zeile[0];
$tabelle [$i]['name'] = $zeile[1];
$i += 1;
}
mysql_free_result($result);
return $tabelle;
}
}
// ---------------------------------------------------------------------
// This function generates the postcount of a user.
// ---------------------------------------------------------------------
function get_postcount($user)
{
$sql = "SELECT COUNT(post_id) FROM " . POSTS_TABLE . " WHERE poster_id=$user";
$result = mysql_query($sql);
if(!$result) {
die("***** ERROR: Cannot count post_id<br>");
}
else {
$zeile = mysql_fetch_row ($result);
$anzahl = $zeile[0];
}
mysql_free_result($result);
return $anzahl;
}
// ---------------------------------------------------------------------
// This function updates the postcount of a user.
// ---------------------------------------------------------------------
function update_postcount($user, $count)
{
$ok = true;
$sql = "UPDATE " . USERS_TABLE . " SET user_posts=$count WHERE user_id=$user";
$result = mysql_query($sql);
if(!$result) {
$ok = false;
}
mysql_free_result($result);
return $ok;
}
// ---------------------------------------------------------------------
// Some database functions.
// ---------------------------------------------------------------------
function open_db()
{
global $db;
global $dbhost;
global $dbuser;
global $dbpasswd;
global $dbname;
$db = mysql_connect($dbhost, $dbuser, $dbpasswd);
if (!$db) {
die ("***** ERROR: Cannot connect database<br>");
}
if (!mysql_select_db($dbname)) {
die ("***** ERROR: Cannot open database<br>");
}
}
function close_db()
{
global $db;
if (!mysql_close($db)) {
die ("***** ERROR: Cannot close database<br>");
}
}
// ---------------------------------------------------------------------
// End Functions
// ---------------------------------------------------------------------
//
// Begin program ******************************************************
//
echo "***** start repair_postercount at $startdate<br>";
open_db();
$usertab = get_usertable();
foreach ($usertab as $user) {
$id = $user['id'];
$name = $user['name'];
$postcount = get_postcount($id);
if (update_postcount($id, $postcount)) {
echo "user $id ($name) updated with $postcount posts<br>";
}
else {
echo "user $user cannot be updated<br>";
}
}
close_db();
echo "***** stop repair_postercount<br>";
?>