Topic: Updating a db count
Another of my infamous quick jobs. Can anyone tell me why this isn't incrementing the topic count by 1 on each loop? I honestly can't spot where the problem is with this.
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
$topic_array = array(1, 2);
$result = $db->query('SELECT u.id AS uid, t.poster FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'users AS u ON u.username=t.poster WHERE t.forum_id IN ('.implode(', ', $topic_array).')') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
{
message('No topic info');
}
else
{
while($topic = $db->fetch_assoc($result))
{
$db->query('UPDATE '.$db->prefix.'users SET num_topics=num_topics+1 WHERE id='.$topic['uid']) or error('Unable to update topic counts', __FILE__, __LINE__, $db->error());
echo 'Topic poster: '.$topic['poster'].' Uid: '.$topic['uid']."\n";
}
}
?>
The echo is outputting the username and uid fine, but the count is not incrementing. Btw, that db lookup is only like that because I've been playing around. I've tried it using both just the username and then with the above using uid and/or username, so I know that lookup is excessive.
I'm at a total loss as to where the problem is with this one.
Cheers,
Matt