I've got a function in my mybb-forum. It's part of a plugin that tracks relies to certain forums and displays the date in on the memberpage (among other things).
This part is for when a user deleted his post. It's supposed to then find the last post before the deleted one in the set forums and to display that (older) date on the memberpage of that user.
However the update-query does not work and I don't know what the problem is.
Here is my code. There is no error but it does not write into the database either.
function lastippost_update($pid)
{
global $db, $mybb;
$query = $db->simple_select("posts","fid,uid,dateline","pid='{$pid}'");
$post = $db->fetch_array($query);
if ($mybb->settings['lastippost'] != '')
{
$ipids = $mybb->settings['lastippost'];
if (in_array($post['fid'], $ipids))
{
$ipquery = $db->write_query("SELECT uid,dateline FROM ".TABLE_PREFIX."posts WHERE fid IN ($ipids) AND uid='".$post['uid']."' ORDER BY dateline DESC LIMIT 1 OFFSET 1");
$ippost = $db->fetch_array($ipquery);
$db->update_query("users", array('lastippost' => $ippost['dateline']), "uid='".$ippost['uid']."'");
}
}
}
$ipids is a comma-separated list of forum ids.
I dunno if that helps but I have another bit of rather similar code that does work:
$ipids = $mybb->settings['lastippost'];
$ipquery = $db->write_query("SELECT uid, dateline FROM ".TABLE_PREFIX."posts WHERE fid IN ($ipids) ORDER BY uid,dateline DESC");
while ($ippost = mysql_fetch_assoc($ipquery))
{
if($ippost['uid'] != $lastuid)
{
$db->update_query("users", array('lastippost' => $ippost['dateline']), "uid='".$ippost['uid']."'");
}
$lastuid = $ippost['uid'];
}
OK i found my problem:
$ipids = $mybb->settings['lastippost'];
The above is a string. I need it to be for the select query. But this part hier obviously refers to an array:
if (in_array($post['fid'], $ipids))
It may not be the best solution but now I've done something like this and it works:
$ipids = $mybb->settings['lastippost'];
$ipids2 = explode(",", trim($ipids));
The first is used for the select query and the second one for the in_array
Thanks for the help! (I'm still open to suggestions for more elegant solutions :) )