Quote:
Originally Posted by thincom2000
Hm... I could join those first three queries for you if you so desire.
In fact I already did. Your new countupdate.php should be the following:
PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ############# REQUIRE BACK-END #######################
require_once('./global.php');
// ############# UPDATE PM COUNTS IN USER TABLE #######################
if($vbulletin->userinfo['usergroupid'] != '6'){
exit();
}
// Get all users PMs
$pmdata = $db->query_first("
SELECT user.userid, user.pmtotal, user.pmunread,
pm.pmunread AS pmsunread, pm.pmid
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "pm AS pm ON(pm.userid = user.userid)
WHERE user.userid != 0
ORDER BY user.userid ASC
");
while ($pms = $db->fetch_array($pmdata))
{
$lastuser = ($lastuser == $pms['userid']) ? true : false;
$pmtotal = $lastuser ? $pmtotal : 0;
$pmunread = $lastuser ? $pmunread : 0;
if ($pms['pmid'])
{
$pmtotal++;
if ($pms['pmsunread'])
{
$pmunread++;
}
}
$pmusers["$pms[userid]"] = array(
'true_total' => $pmtotal,
'user_total' => $pms['pmtotal'],
'true_unread' => $pmunread,
'user_unread' => $pms['pmunread']
);
}
$db->free_result($pmdata);
unset($pms, $pmtotal, $pmunread, $lastuser);
foreach ($pmusers AS $pmuserid => $pminfo)
{
if (($pminfo['true_total'] != $pminfo['user_total']) OR ($pminfo['true_unread'] != $pminfo['user_unread']))
{
$db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET pmtotal = $pminfo[true_total],
pmunread = $pminfo[true_unread]
WHERE userid = $pmuserid
");
echo "USERID $pmuserid was updated!<br />";
}
}
unset($pmuserid, $pminfo, $pmusers);
echo 'All Done!';
?>
|
Well, not quite...
I tested and this generates an error...
Database error in vBulletin 3.6.4:
Invalid SQL:
SELECT user.userid, user.pmtotal, user.pmunread,
pm.pmunread AS pmsunread, pm.pmid
FROM user AS user
LEFT JOIN pm AS pm ON(pm.userid = user.userid)
WHERE user.userid != 0
ORDER BY user.userid ASC;
MySQL Error : Unknown column 'pm.pmunread' in 'field list'
Error Number : 1054
Date : Thursday, February 8th 2007 @ 09:11:45 PM
Script :htt p://www.XXXXXXX.com/forums/countupdate.php
Referrer :
IP Address : 72.94.246.202
Username : Quarterbore
Classname : vb_database
I am trying to find the issue byt MYSQL is not my strong point.
EDIT - This is why I did the simple code I did... even with my MYSQL manuals I can not fix this... I need some sleep but thanks for the kindness... I just had a rough 24-hrs of bringing back a crashed forum and too little sleep...