PDA

View Full Version : Help writing a query


G_Man
10-02-2006, 07:34 PM
I want to set up a cron job for this, but not sure how to do the query.

I want to reduce every users Rep by a certain amount, say 10, who has not logged in for over 24 hours.

Guessing it involves updating the User Rep table using a conditional of useractivity, but...

I'd appreciate anyone who KNOWS how to write this query so I can insert into a daily cron.

Cheers,

G_Man.

G_Man
10-05-2006, 11:15 PM
<font size="2">umm... help?</font>

Adrian Schneider
10-06-2006, 12:22 AM
Not tested... <?php

if (!is_object($vbulletin->db))
{
exit;
}

$removePoints = 10;
$daysInactive = 1;

$cutOff = TIMENOW - (86400 * $daysInactive);

$result = $vbulletin->db->query_read("
SELECT userid
FROM " . TABLE_PREFIX . "user
WHERE lastactivity < $cutOff
");

while ($user = $vbulletin->db->fetch_array($result))
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET reputation = reputation - $removePoints
WHERE userid = $user[userid]
");
}

?>You'll have to update their reputationlevelid as well... don't have time to look into that though.

G_Man
10-06-2006, 02:09 AM
Not tested... <?php

if (!is_object($vbulletin->db))
{
exit;
}

$removePoints = 10;
$daysInactive = 1;

$cutOff = TIMENOW - (86400 * $daysInactive);

$result = $vbulletin->db->query_read("
SELECT userid
FROM " . TABLE_PREFIX . "user
WHERE lastactivity < $cutOff
");

while ($user = $vbulletin->db->fetch_array($result))
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET reputation = reputation - $removePoints
WHERE userid = $user[userid]
");
}

?>You'll have to update their reputationlevelid as well... don't have time to look into that though.


CHEERS!!

Works a treat.

Paul M
10-06-2006, 03:09 AM
I'm pretty sure you could reduce the active part to just one query ;


$days = 1;
$points = 10;

$cutoff = TIMENOW - (86400 * $days);

$vbulletin->db->query_write("
UPDATE ".TABLE_PREFIX."user
SET reputation = reputation - $points
WHERE lastactivity < $cutoff
");


You do realise that if someone doesn't ever login again - then their reputation is just going to get more and more negative each day.

G_Man
10-06-2006, 03:42 AM
I'm pretty sure you could reduce the active part to just one query ;


$days = 1;
$points = 10;

$cutoff = TIMENOW - (86400 * $days);

$vbulletin->db->query_write("
UPDATE ".TABLE_PREFIX."user
SET reputation = reputation - $points
WHERE lastactivity < $cutoff
");


You do realise that if someone doesn't ever login again - then their reputation is just going to get more and more negative each day.


Yep... I'll prune them at some point anyway.

Thanks for the alternative code, too, Paul. :)

Chicago_VLNU_4s
10-23-2006, 07:52 AM
interesting.. so where does this go?

Adrian Schneider
10-23-2006, 07:58 AM
As a new cron job probably (new file).